SmallestTemperatureSpread { public Optional<Integer> minTemperatureSpreadDay() throws IOException { List<TemperatureExtremum> extrema = weatherFileReader.readFile(); return extrema.stream() .sorted() .findFirst() .map(TemperatureExtremum::getDay); }  Optional<Integer> minTemperatureSpreadDay();  }
@Test public void should_find_day_of_the_smallest_temperature_in_extremum_value() throws IOException { List<TemperatureExtremum> extrema = newArrayList( new TemperatureExtremum(1, 88, 59), new TemperatureExtremum(2, 79, 53)); doReturn(extrema).when(weatherFileReader).readFile(); Optional<Integer> minTemperaturesSpread = smallestTemperatureSpread.minTemperatureSpreadDay(); assertThat(minTemperaturesSpread).hasValue(2); }
@Test public void with_empty_file() throws IOException { URL weatherFile = getResource("empty.dat"); WeatherFileLineProcessor weatherFileLineProcessor = new WeatherFileLineProcessor(); WeatherFileReader weatherFileReader = new WeatherFileReader(weatherFile, weatherFileLineProcessor); SmallestTemperatureSpread smallestTemperatureSpread = new SmallestTemperatureSpread(weatherFileReader); Optional<Integer> minTemperatureSpreadDay = smallestTemperatureSpread.minTemperatureSpreadDay(); assertThat(minTemperatureSpreadDay).isEmpty(); }
@Test public void acceptance() throws IOException { URL weatherFile = getResource("weather.dat"); WeatherFileLineProcessor weatherFileLineProcessor = new WeatherFileLineProcessor(); WeatherFileReader weatherFileReader = new WeatherFileReader(weatherFile, weatherFileLineProcessor); SmallestTemperatureSpread smallestTemperatureSpread = new SmallestTemperatureSpread(weatherFileReader); Optional<Integer> minTemperatureSpreadDay = smallestTemperatureSpread.minTemperatureSpreadDay(); assertThat(minTemperatureSpreadDay).hasValue(14); }