@Test
  public void shouldCreateAStreamForEachSensor() {
    sessionManager.startMobileSession(false);

    triggerMeasurement();
    SensorEvent event =
        new SensorEvent("CERN", "LHC2", "Siggh boson", "SB", "number", "#", 1, 2, 3, 4, 5, 10);
    sessionManager.onEvent(event);

    MeasurementStream expected = event.stream();
    assertThat(sessionManager.getMeasurementStreams(), hasItem(expected));
  }
  @Test
  public void should_not_crashOnDeletedSensor() throws Exception {
    // given
    SensorEvent event =
        new SensorEvent("CERN", "LHC", "Siggh boson", "SB", "number", "#", 1, 2, 3, 4, 5, 10);
    sessionManager.onEvent(event);

    // when
    sessionManager.deleteSensorStream(event.getSensorName());

    // then (shouldn't crash)
    sessionManager.onEvent(event);
  }
  private MeasurementStream prepareStream(SensorEvent event) {
    String sensorName = event.getSensorName();

    if (!session.hasStream(sensorName)) {
      MeasurementStream stream = event.stream();
      tracker.addStream(stream);
    }

    MeasurementStream stream = session.getStream(sensorName);
    if (stream.isVisible()) {
      stream.markAs(MeasurementStream.Visibility.VISIBLE_RECONNECTED);
    }

    return stream;
  }
  @Test
  public void shouldCreateMeasurementStreams() {
    sessionManager.startMobileSession(false);

    triggerMeasurement();

    MeasurementStream expected = lastEvent.stream();
    Collection<MeasurementStream> streams = sessionManager.getMeasurementStreams();

    assertThat(streams, hasItem(expected));
  }
  @Subscribe
  public synchronized void onEvent(SensorEvent event) {
    event = sensorEventTransformer.transform(event);

    double value = event.getValue();
    String sensorName = event.getSensorName();
    Sensor sensor = sensorManager.getSensorByName(sensorName);
    recentMeasurements.put(sensorName, value);

    Location location = getLocation();
    if (location != null && sensor != null && sensor.isEnabled()) {
      double latitude = location.getLatitude();
      double longitude = location.getLongitude();
      Measurement measurement =
          new Measurement(latitude, longitude, value, event.getMeasuredValue(), event.getDate());
      if (state.recording().isRecording()) {
        MeasurementStream stream = prepareStream(event);
        tracker.addMeasurement(stream, measurement);
      }
      eventBus.post(new MeasurementEvent(measurement, sensor));
    }
  }