Commit 78dbaf9b authored by João Lino's avatar João Lino

remove fails, use asserts

parent cec5c367
......@@ -7,7 +7,6 @@ import org.junit.Before;
import org.junit.Test;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.Assert.*;
......@@ -70,45 +69,35 @@ public class TestScoreboard {
@Test
public void shouldFinishAGame_whenGameHasBeenStarted() {
IMatch match = scoreboard.startMatch(Mexico, Canada);
if (match != scoreboard.finishMatch(match)) {
fail("unable to finish game");
}
assertEquals(match, scoreboard.finishMatch(match));
}
// should throw NoSuchElementException match is not ongoing
@Test
public void shouldThrowNoSuchElementException_whenMatchNotFound() {
Match match = new Match(Mexico, Canada);
try {
scoreboard.finishMatch(match);
fail("exception was not thrown");
} catch (NoSuchElementException ignored) {}
assertThrows(NoSuchElementException.class, () -> scoreboard.finishMatch(match));
}
// summary should be empty when no match has started
@Test
public void shouldBeEmptySummary_whenNoMatchHasStarted() {
if(!scoreboard.getGameSummary().isEmpty()) {
fail("Summary was not empty on creation.");
}
assertTrue(scoreboard.getGameSummary().isEmpty());
}
// should get game in summary when the game has been started before
@Test
public void shouldGetGameInSummary_whenGameHasBeenStarted() {
IMatch match = scoreboard.startMatch(Mexico, Canada);
if (match != scoreboard.getGameSummary().get(0)) {
fail("unable to get single ongoing game");
}
assertEquals(match, scoreboard.getGameSummary().get(0));
}
// score for a match that just started should be 0-0
@Test
public void scoreShouldBeZeroZero_whenMatchJustStarted() {
IMatch match = scoreboard.startMatch(Mexico, Canada);
if (match.getHomeTeamScore().getGoals() != 0 || match.getAwayTeamScore().getGoals() != 0) {
fail("initial score was not 0-0");
}
assertEquals(Integer.valueOf(0), match.getHomeTeamScore().getGoals());
assertEquals(Integer.valueOf(0), match.getAwayTeamScore().getGoals());
}
// score increase for home team when home team score is updated to + 1
......@@ -117,9 +106,8 @@ public class TestScoreboard {
IMatch match = scoreboard.startMatch(Mexico, Canada);
IScore updatedHomeTeamScore = new Score(match.getHomeTeamScore().getGoals() + 1);
scoreboard.updateScore(match, updatedHomeTeamScore, match.getAwayTeamScore());
if (match.getHomeTeamScore().getGoals() != 1 || match.getAwayTeamScore().getGoals() != 0) {
fail("updated score was not 1-0");
}
assertEquals(Integer.valueOf(1), match.getHomeTeamScore().getGoals());
assertEquals(Integer.valueOf(0), match.getAwayTeamScore().getGoals());
}
// should present matches ordered from newest to oldest when summary is requested
......@@ -136,13 +124,9 @@ public class TestScoreboard {
IMatch match5 = scoreboard.startMatch(Argentina, Australia);
match5 = scoreboard.updateScore(match5, new Score(5), new Score(5));
ArrayList<IMatch> expectedResult = Stream.of(match5, match4, match3, match2, match1).collect(Collectors.toCollection(ArrayList::new));
ArrayList<IMatch> gameSummary = scoreboard.getGameSummary();
if (!expectedResult.equals(gameSummary)) {
gameSummary.forEach(System.out::println);
fail("failed to return expected ordered summary");
}
Object[] expectedResult = Stream.of(match5, match4, match3, match2, match1).toArray();
Object[] gameSummary = scoreboard.getGameSummary().toArray();
assertArrayEquals(expectedResult, gameSummary);
}
// should present matches ordered from highest combined score to lowest, newest to oldest on collision, when summary is requested
......@@ -159,12 +143,8 @@ public class TestScoreboard {
IMatch match5 = scoreboard.startMatch(Argentina, Australia);
match5 = scoreboard.updateScore(match5, new Score(3), new Score(1));
ArrayList<IMatch> expectedResult = Stream.of(match4, match2, match1, match5, match3).collect(Collectors.toCollection(ArrayList::new));
ArrayList<IMatch> gameSummary = scoreboard.getGameSummary();
if (!expectedResult.equals(gameSummary)) {
gameSummary.forEach(System.out::println);
fail("failed to return expected ordered summary");
}
Object[] expectedResult = Stream.of(match4, match2, match1, match5, match3).toArray();
Object[] gameSummary = scoreboard.getGameSummary().toArray();
assertArrayEquals(expectedResult, gameSummary);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment