### Question:
ForecastUtil { public static Set<WeatherForecastPerDay> calculateWeatherForDays(WeatherForecastDbHelper.WeatherForecastRecord weatherForecastRecord) { Set<WeatherForecastPerDay> result = new HashSet<>(); Calendar forecastCalendar = Calendar.getInstance(); int initialYearForTheList = forecastCalendar.get(Calendar.YEAR); Map<Integer, List<DetailedWeatherForecast>> weatherList = createWeatherList(weatherForecastRecord); Integer firstDayOfYear = Collections.min(weatherList.keySet()); int dayCounter = 0; int daysInList = firstDayOfYear + weatherList.keySet().size(); for (int dayInYear = firstDayOfYear; dayInYear < daysInList; dayInYear++) { int dayInYearForList; int yearForList; if (dayInYear > 365) { dayInYearForList = dayInYear - 365; yearForList = initialYearForTheList + 1; } else { dayInYearForList = dayInYear; yearForList = initialYearForTheList; } if ((weatherList.get(dayInYear) == null) || (weatherList.get(dayInYear).size() < 3)) { continue; } dayCounter++; WeatherMaxMinForDay weatherMaxMinForDay = calculateWeatherMaxMinForDay(weatherList.get(dayInYear)); if (weatherMaxMinForDay == null) { continue; } WeatherIdsForDay weatherIdsForTheDay = getWeatherIdForDay(weatherList.get(dayInYear), weatherMaxMinForDay); result.add(new WeatherForecastPerDay(dayCounter, weatherIdsForTheDay, weatherMaxMinForDay, getWeatherIconId(weatherIdsForTheDay.mainWeatherId, weatherList.get(dayInYear)), dayInYearForList, yearForList)); } return result; }  static boolean shouldUpdateForecast(Context context, long locationId, int forecastType); static Set<WeatherForecastPerDay> calculateWeatherForDays(WeatherForecastDbHelper.WeatherForecastRecord weatherForecastRecord); static Map<Integer, List<DetailedWeatherForecast>> createWeatherList(WeatherForecastDbHelper.WeatherForecastRecord weatherForecastRecord); static WeatherIdsForDay getWeatherIdForDay(List<DetailedWeatherForecast> weatherListForDay,
                                                      WeatherMaxMinForDay weatherMaxMinForDay); static WeatherForecastForVoice calculateWeatherVoiceForecast(Context context, Long locationId); static Map<Integer, List<DetailedWeatherForecast>> getOneDayForecast(WeatherForecastDbHelper.WeatherForecastRecord weatherForecastRecord); static WeatherMaxMinForDay calculateWeatherMaxMinForDay(List<DetailedWeatherForecast> forecastListForDay); static String getWeatherIconId(int weatherId, List<DetailedWeatherForecast> forecastListForDay); static long AUTO_FORECAST_UPDATE_TIME_MILIS; }### Answer:
@Test public void calculateMaxTemperatureWhenAllValuesAreNegative() throws Exception { createDetailedWeatherForecastForDayWithNegativeTemperatures(); Set<ForecastUtil.WeatherForecastPerDay> result = ForecastUtil.calculateWeatherForDays(weatherForecastRecord); assertEquals(1, result.size()); ForecastUtil.WeatherForecastPerDay firstDay = result.iterator().next(); assertTrue(firstDay.weatherMaxMinForDay.maxTemp > firstDay.weatherMaxMinForDay.minTemp); assertTrue(0 > firstDay.weatherMaxMinForDay.minTemp); assertTrue(0 > firstDay.weatherMaxMinForDay.maxTemp); }
@Test public void createForecastFor5DaysAtTheEndOfYear() throws Exception { createDetailedWeatherForecastForDay(); Set<ForecastUtil.WeatherForecastPerDay> result = ForecastUtil.calculateWeatherForDays(weatherForecastRecord); assertEquals(5, result.size()); }