InlinedFootball { public static Optional<String> teamWithMinimumGoalDifference(URL footballFile) throws IOException { Optional<TeamResult> teamResult = MinimumDifferenceInFile.minimum(footballFile, (datas) -> { String team = datas.get(1); try { int numberOfGoalsFor = Integer.parseInt(datas.get(6)); int numberOfGoalsAgainst = Integer.parseInt(datas.get(7)); return Optional.of(new TeamResult(team, numberOfGoalsFor, numberOfGoalsAgainst)); } catch (NumberFormatException e) { return empty(); } }); return teamResult.map(TeamResult::getTeam); }  static Optional<String> teamWithMinimumGoalDifference(URL footballFile);  }
@Test public void acceptance() throws IOException { URL footballFile = getResource("football.dat"); Optional<String> teamWithMinimumGoalDifference = InlinedFootball.teamWithMinimumGoalDifference(footballFile); assertThat(teamWithMinimumGoalDifference).isPresent().hasValue("Aston_Villa"); }
@Test public void with_empty_file() throws IOException { URL footballFile = getResource("empty.dat"); Optional<String> teamWithMinimumGoalDifference = InlinedFootball.teamWithMinimumGoalDifference(footballFile); assertThat(teamWithMinimumGoalDifference).isEmpty(); }