diff options
author | jbion <joffrey.bion@amadeus.com> | 2016-12-24 13:46:36 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2016-12-24 13:55:28 +0100 |
commit | e5884d6183388487ccdab843edc076e3567d1d0b (patch) | |
tree | a77c79a150d2f5cff5987518493d53467ddc0559 /src/test/java/org/luxons/sevenwonders | |
parent | Remove useless toString() methods (diff) | |
download | seven-wonders-e5884d6183388487ccdab843edc076e3567d1d0b.tar.gz seven-wonders-e5884d6183388487ccdab843edc076e3567d1d0b.tar.bz2 seven-wonders-e5884d6183388487ccdab843edc076e3567d1d0b.zip |
Add tests for Card.equals() and Card.hashcode()
Diffstat (limited to 'src/test/java/org/luxons/sevenwonders')
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java | 52 | ||||
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 4 |
2 files changed, 55 insertions, 1 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java index a655fd87..0748f005 100644 --- a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java @@ -14,7 +14,8 @@ import org.luxons.sevenwonders.game.effects.ProductionIncrease; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.wonders.Wonder; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; +import static org.luxons.sevenwonders.game.test.TestUtils.*; public class CardTest { @@ -53,4 +54,53 @@ public class CardTest { assertEquals(3, table.getBoard(1).getGold()); assertEquals(3, table.getBoard(2).getGold()); } + + @Test + public void equals_falseWhenNull() { + Card card = createCard("TestCard"); + //noinspection ObjectEqualsNull + assertFalse(card.equals(null)); + } + + @Test + public void equals_falseWhenDifferentClass() { + Card card = createCard("TestCard"); + Object object = new Object(); + //noinspection EqualsBetweenInconvertibleTypes + assertFalse(card.equals(object)); + } + + @Test + public void equals_trueWhenSame() { + Card card = createCard("TestCard"); + assertEquals(card, card); + } + + @Test + public void equals_trueWhenSameContent() { + Card card1 = createCard("TestCard"); + Card card2 = createCard("TestCard"); + assertTrue(card1.equals(card2)); + } + + @Test + public void equals_falseWhenDifferentName() { + Card card1 = createCard("TestCard1"); + Card card2 = createCard("TestCard2"); + assertFalse(card1.equals(card2)); + } + + @Test + public void hashCode_sameWhenSameContent() { + Card card1 = createCard("TestCard"); + Card card2 = createCard("TestCard"); + assertEquals(card1.hashCode(), card2.hashCode()); + } + + @Test + public void hashCode_differentWhenDifferentName() { + Card card1 = createCard("TestCard1"); + Card card2 = createCard("TestCard2"); + assertNotEquals(card1.hashCode(), card2.hashCode()); + } } diff --git a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 2f4fd13a..1f2df0ab 100644 --- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -114,6 +114,10 @@ public class TestUtils { return sampleCards; } + public static Card createCard(String name) { + return new Card(name, Color.BLUE, new Requirements(), null, null, null, null); + } + private static Card createCard(int num, Color color) { return new Card("Test Card " + num, color, new Requirements(), null, null, null, null); } |