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