public double getPeak(Sensor sensor) { String sensorName = sensor.getSensorName(); if (session.hasStream(sensorName)) { return session.getStream(sensorName).getPeak(); } else { return 0; } }
@Test public void shouldProvidePeakForEachStream() { MeasurementStream stream = mock(MeasurementStream.class); when(stream.getPeak()).thenReturn(11.0); String name = sensor.getSensorName(); when(stream.getSensorName()).thenReturn(name); sessionManager.session.add(stream); assertThat(sessionManager.getPeak(sensor), equalTo(11.0)); }
public List<Measurement> getMeasurements(Sensor sensor) { String name = sensor.getSensorName(); if (session.hasStream(name)) { MeasurementStream stream = session.getStream(name); return stream.getMeasurements(); } else { return newArrayList(); } }
@Test public void shouldStoreLastMeasurementForEachSensor() { triggerMeasurement("LHC", 150); triggerMeasurement("LHC2", 123); Sensor sensor2 = mock(Sensor.class); when(sensor2.getSensorName()).thenReturn("LHC2"); assertThat(sessionManager.getNow(sensor), equalTo(150.0)); assertThat(sessionManager.getNow(sensor2), equalTo(123.0)); }
private void mockSensors() { sessionManager.locationHelper = mock(LocationHelper.class); sessionManager.audioReader = mock(SimpleAudioReader.class); sessionManager.externalSensors = mock(ExternalSensors.class); sessionManager.eventBus = mock(EventBus.class); sessionManager.sensorManager = mock(SensorManager.class); sensor = mock(Sensor.class); when(sensor.isEnabled()).thenReturn(true); when(sensor.getSensorName()).thenReturn("LHC"); when(sessionManager.locationHelper.getLastLocation()).thenReturn(location); when(sessionManager.sensorManager.getSensorByName(Mockito.any(String.class))) .thenReturn(sensor); }
public void deleteSensorStream(Sensor sensor) { String sensorName = sensor.getSensorName(); deleteSensorStream(sensorName); }
public synchronized double getNow(Sensor sensor) { if (!recentMeasurements.containsKey(sensor.getSensorName())) { return 0; } return recentMeasurements.get(sensor.getSensorName()); }