WeatherService { public void setDataPoint(String iataCode, DataPointType type, DataPoint dataPoint) { Airport airport = repository.getAirport(iataCode); Weather weather = airport.getWeather(); if (! type.isValid(dataPoint.getMean())) { throw new WeatherException("Illegal mean value for data point type " + type + ": " + dataPoint.getMean()); } switch (type) { case WIND: weather.setWind(dataPoint); break; case TEMPERATURE: weather.setTemperature(dataPoint); break; case HUMIDTY: weather.setHumidity(dataPoint); break; case PRESSURE: weather.setPressure(dataPoint); break; case CLOUDCOVER: weather.setCloudCover(dataPoint); break; case PRECIPITATION: weather.setPrecipitation(dataPoint); break; default: throw new WeatherException("Not implemented"); } weather.setLastUpdateTime(System.currentTimeMillis()); log.debug("Successfully updated " + type + " for airport " + iataCode); }  @PostConstruct void loadDefaultAirports(); void resetData(); void setDataPoint(String iataCode, DataPointType type, DataPoint dataPoint); Airport createAirport(String iataCode, double latitude, double longitude); List<Weather> searchAirportWeather(String iataCode, double radiusKm); Airport findAirport(String iataCode); double calculateHaversineDistance(Airport a1, Airport a2); Set<String> getAllIataCodes(); void deleteAirport(String iataCode); void createAirport(Airport airport);  }
@Test(expected = WeatherException.class) public void setInvalidDataPointThrowsError() { assertNull(airport.getWeather().getPrecipitation()); target.setDataPoint("code1", DataPointType.PRECIPITATION, new DataPoint.Builder().withMean(400).build()); }
@Test public void setValidDataPointSavesAndUpdateLastUpdateTime() { assertNull(airport.getWeather().getPrecipitation()); assertEquals(0, airport.getWeather().getLastUpdateTime()); target.setDataPoint("code1", DataPointType.PRECIPITATION, new DataPoint.Builder().withMean(50).build()); assertNotNull(airport.getWeather().getPrecipitation()); assertEquals(50, airport.getWeather().getPrecipitation().getMean(), EPSILON); assertNotNull(airport.getWeather().getLastUpdateTime()); }