SmallestGoalDifference { public Optional<String> teamWithMinimumGoalDifference() throws IOException { List<TeamResult> extrema = footballFileReader.readFile(); return extrema.stream() .sorted() .findFirst() .map(TeamResult::getTeam); }  Optional<String> teamWithMinimumGoalDifference();  }
@Test public void should_find_team_with_the_smallest_goal_difference_in_football_league() throws IOException { List<TeamResult> footballLeagueResults = newArrayList( new TeamResult("Arsenal", 79, 36), new TeamResult("Liverpool", 67, 30)); doReturn(footballLeagueResults).when(footballFileReader).readFile(); Optional<String> teamWithMinimumGoalDifference = smallestGoalDifference.teamWithMinimumGoalDifference(); assertThat(teamWithMinimumGoalDifference).hasValue("Liverpool"); }
@Test public void with_empty_file() throws IOException { URL footballFile = getResource("empty.dat"); FootballFileLineProcessor footballFileLineProcessor = new FootballFileLineProcessor(); FootballFileReader footballFileReader = new FootballFileReader(footballFile, footballFileLineProcessor); SmallestGoalDifference smallestGoalDifference = new SmallestGoalDifference(footballFileReader); Optional<String> teamWithMinimumGoalDifference = smallestGoalDifference.teamWithMinimumGoalDifference(); assertThat(teamWithMinimumGoalDifference).isEmpty(); }
@Test public void acceptance() throws IOException { URL footballFile = getResource("football.dat"); FootballFileLineProcessor footballFileLineProcessor = new FootballFileLineProcessor(); FootballFileReader footballFileReader = new FootballFileReader(footballFile, footballFileLineProcessor); SmallestGoalDifference smallestGoalDifference = new SmallestGoalDifference(footballFileReader); Optional<String> teamWithMinimumGoalDifference = smallestGoalDifference.teamWithMinimumGoalDifference(); assertThat(teamWithMinimumGoalDifference).hasValue("Aston_Villa"); }