### Question:
JpaStorage implements Storage { @Override public List<RelatedObservation> getRelatedObservations(String sensorName, Date startDate, Date stopDate) { final String s1 = TimeUtil.formatCcsdsUtcFormat(startDate); final String s2 = TimeUtil.formatCcsdsUtcFormat(stopDate); final String queryString = SENSOR_OBSERVATION_QUERY_TEMPLATE_STRING .replaceAll("\\?2", "'" + s1 + "'") .replaceAll("\\?3", "'" + s2 + "'"); final Query query = persistenceManager.createNativeQuery(queryString, RelatedObservation.class); query.setParameter(1, sensorName); return query.getResultList(); } JpaStorage(PersistenceManager persistenceManager); @Override DataFile getDatafile(int id); @Override final DataFile getDatafile(final String path); @Override DataFile getDatafileWithTransaction(String path); void store(DataFile dataFile); @Override int storeWithTransaction(DataFile dataFile); @Override Observation getObservation(int id); @Override RelatedObservation getRelatedObservation(int id); @Override ReferenceObservation getReferenceObservation(int id); @Override final Sensor getSensor(final String sensorName); @Override Sensor getSensorWithTransaction(String sensorName); @Override void storeWithTransaction(Sensor sensor); @Override List<RelatedObservation> getRelatedObservations(String sensorName, Date startDate, Date stopDate); @Override void store(InsituObservation insituObservation);  }### Answer:
@Test public void testGetRelatedObservations() throws ParseException { final Date startDate = TimeUtil.parseCcsdsUtcFormat("2010-01-01T13:00:00Z"); final Date stoptDate = TimeUtil.parseCcsdsUtcFormat("2010-01-05T17:00:00Z"); final String sensorName = "thermometer"; final String sql = "select o.id from mm_observation o where o.sensor = ?1 and o.time >= timestamp '2010-01-01T13:00:00Z' and o.time < timestamp '2010-01-05T17:00:00Z' order by o.time, o.id"; final List<RelatedObservation> observations = new ArrayList<>(); final RelatedObservation observation = new RelatedObservation(); observation.setName("tested thing"); observations.add(observation); final Query query = mock(Query.class); when(query.getResultList()).thenReturn(observations); when(persistenceManager.createNativeQuery(sql, RelatedObservation.class)).thenReturn(query); final List<RelatedObservation> storedObservations = jpaStorage.getRelatedObservations(sensorName, startDate, stoptDate); assertNotNull(storedObservations); assertEquals(1, storedObservations.size()); verify(persistenceManager, times(1)).createNativeQuery(sql, RelatedObservation.class); verifyNoMoreInteractions(persistenceManager); verify(query, times(1)).setParameter(1, sensorName); verify(query, times(1)).getResultList(); verifyNoMoreInteractions(query); }