aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/eu/equalparts/cardbase/CardbaseSortTest.java (renamed from test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerSortTest.java)7
-rw-r--r--test/eu/equalparts/cardbase/CardbaseTest.java132
-rw-r--r--test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java131
-rw-r--r--test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java170
4 files changed, 136 insertions, 304 deletions
diff --git a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerSortTest.java b/test/eu/equalparts/cardbase/CardbaseSortTest.java
index 990cad5..f0d87a1 100644
--- a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerSortTest.java
+++ b/test/eu/equalparts/cardbase/CardbaseSortTest.java
@@ -1,4 +1,4 @@
-package eu.equalparts.cardbase.cardstorage;
+package eu.equalparts.cardbase;
import static org.junit.Assert.assertTrue;
@@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.equalparts.cardbase.Cardbase;
import eu.equalparts.cardbase.cards.Card;
+import eu.equalparts.cardbase.cardstorage.StandaloneCardContainer;
/**
* Tests the sorting functionality.
@@ -22,7 +23,7 @@ import eu.equalparts.cardbase.cards.Card;
* @author Eduardo Pedroni
*
*/
-public class StandaloneCardContainerSortTest {
+public class CardbaseSortTest {
private StandaloneCardContainer uut;
private static List<Card> testCards;
@@ -30,7 +31,7 @@ public class StandaloneCardContainerSortTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ObjectMapper mapper = new ObjectMapper();
- testCards = mapper.readValue(StandaloneCardContainerSortTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {});
+ testCards = mapper.readValue(CardbaseSortTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {});
}
@AfterClass
diff --git a/test/eu/equalparts/cardbase/CardbaseTest.java b/test/eu/equalparts/cardbase/CardbaseTest.java
index 47ad027..d5fc8e2 100644
--- a/test/eu/equalparts/cardbase/CardbaseTest.java
+++ b/test/eu/equalparts/cardbase/CardbaseTest.java
@@ -2,10 +2,13 @@ package eu.equalparts.cardbase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.lang.reflect.Field;
import org.junit.AfterClass;
import org.junit.Before;
@@ -181,4 +184,133 @@ public class CardbaseTest {
exception.expect(NullPointerException.class);
uut = Cardbase.load(null);
}
+
+ /***********************************************************************************
+ * Adding card tests, happy path
+ ***********************************************************************************/
+ @Test
+ public void newCardIsAdded() throws Exception {
+ assertNull("Container should not contain the test card to begin with.", uut.getCard(testCard.setCode, testCard.number));
+
+ uut.addCard(testCard, 1);
+
+ assertEquals("Container should contain the test card once it is added.", testCard, uut.getCard(testCard.setCode, testCard.number));
+ assertEquals("Container should have contained 1 test card.", 1, uut.getCount(testCard));
+ }
+
+ @Test
+ public void existingCardIsIncremented() throws Exception {
+ uut.addCard(testCard, 2);
+ uut.addCard(testCard, 4);
+
+ Card addedCard = uut.getCard(testCard.setCode, testCard.number);
+ assertNotNull("Card was not found in cardbase.", addedCard);
+ assertEquals("Card count was not updated correctly.", 6, uut.getCount(addedCard));
+ }
+
+ /*
+ * Edge cases
+ */
+ @Test
+ public void cardAddedIsNull() throws Exception {
+ exception.expect(NullPointerException.class);
+ uut.addCard(null, 0);
+ }
+
+ /***********************************************************************************
+ * Removing card tests, happy path
+ ***********************************************************************************/
+ @Test
+ public void cardIsStillPresentIfRemoveCountIsLessThanCardCount() throws Exception {
+ uut.addCard(testCard, 5);
+
+ int removed = uut.removeCard(testCard, 3);
+
+ assertEquals("Card count was not updated correctly.", 2, uut.getCount(testCard));
+ assertEquals("Container reports wrong removed count.", 3, removed);
+ assertEquals("Card is missing from container.", testCard, uut.getCard(testCard.setCode, testCard.number));
+ }
+
+ @Test
+ public void cardIsRemovedIfRemoveCountIsEqualToCardCount() throws Exception {
+ uut.addCard(testCard, 5);
+
+ int removed = uut.removeCard(testCard, 5);
+
+ assertEquals("Card was not removed from container.", 0, uut.getCount(testCard));
+ assertEquals("Container reports wrong removed count.", 5, removed);
+ assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
+ }
+
+ @Test
+ public void cardIsRemovedIfRemoveCountIsGreaterThanCardCount() throws Exception {
+ uut.addCard(testCard, 3);
+
+ int removed = uut.removeCard(testCard, 5);
+
+ assertEquals("Card was not removed from container.", 0, uut.getCount(testCard));
+ assertEquals("Container reports wrong removed count.", 3, removed);
+ assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
+ }
+
+ /*
+ * Edge cases
+ */
+ @Test
+ public void removedCardIsNull() throws Exception {
+ exception.expect(NullPointerException.class);
+ uut.removeCard(null, 0);
+ }
+
+ @Test
+ public void removedCardIsNotInContainer() throws Exception {
+ assertNull("Card is not initially missing from container.", uut.getCard(testCard.setCode, testCard.number));
+
+ int removed = uut.removeCard(testCard, 1);
+
+ assertEquals("Removed count should be 0.", 0, removed);
+ assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
+ }
+
+ @Test
+ public void removedCountIsLessThanZero() throws Exception {
+ uut.addCard(testCard, 3);
+
+ int removed = uut.removeCard(testCard, -4);
+
+ assertEquals("Card count in container should be unchanged.", 3, uut.getCount(testCard));
+ assertEquals("Container reports wrong removed count.", 0, removed);
+ assertEquals("Card should not be missing from container.", testCard, uut.getCard(testCard.setCode, testCard.number));
+ }
+
+ /***********************************************************************************
+ * Card getter tests, happy path
+ ***********************************************************************************/
+ @Test
+ public void correctCardIsReturnedByGetter() throws Exception {
+ uut.addCard(testCard, 1);
+
+ Card card = uut.getCard(testCard.setCode, testCard.number);
+
+ for (Field field : Card.class.getFields()) {
+ assertEquals("Field " + field.getName(), field.get(testCard), field.get(card));
+ }
+ }
+
+ @Test
+ public void correctCardCollectionIsReturnedByGetter() throws Exception {
+ uut.addCard(testCard, 1);
+
+ assertTrue("Not all cards were returned by the getter.", uut.getCards().contains(testCard));
+ }
+
+ @Test
+ public void cardCollectionWhenContainerIsEmpty() throws Exception {
+ assertEquals("Returned collection size should have been 0.", 0, uut.getCards().size());
+ }
+
+ @Test
+ public void getCardIsNotInCardbase() throws Exception {
+ assertNull("Method should have returned null", uut.getCard(testCard.setCode, testCard.number));
+ }
}
diff --git a/test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java b/test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java
deleted file mode 100644
index 91409b5..0000000
--- a/test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package eu.equalparts.cardbase.cardstorage;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import eu.equalparts.cardbase.Cardbase;
-import eu.equalparts.cardbase.cards.Card;
-
-/**
- * This test class tests storage-by-reference behaviour only.
- * For standalone storage behaviour tests, see {@code StandaloneCardContainerTest}.
- *
- * @author Eduardo Pedroni
- *
- */
-public class ReferenceCardContainerTest {
- private ReferenceCardContainer uut;
- private static Card testCard;
-
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- ObjectMapper mapper = new ObjectMapper();
- testCard = mapper.readValue(ReferenceCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class);
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- uut = new Cardbase();
- }
-
- /***********************************************************************************
- * Adding card tests, happy path
- ***********************************************************************************/
- @Test
- public void newCardIsAdded() throws Exception {
- uut.addCard(testCard, 1);
-
- assertEquals("Container should have contained 1 test card.", 1, uut.getCount(testCard));
- }
-
- @Test
- public void existingCardIsIncremented() throws Exception {
- uut.addCard(testCard, 2);
- uut.addCard(testCard, 4);
-
- assertEquals("Container should have contained 6 test cards.", 6, uut.getCount(testCard));
- }
-
- /*
- * Edge cases
- */
- @Test
- public void cardAddedIsNull() throws Exception {
- exception.expect(NullPointerException.class);
- uut.addCard(null, 0);
- }
-
- /***********************************************************************************
- * Removing card tests, happy path
- ***********************************************************************************/
- @Test
- public void cardRemoveCountIsLessThanCardCount() throws Exception {
- uut.addCard(testCard, 5);
-
- int removed = uut.removeCard(testCard, 3);
-
- assertEquals("Card count was not updated correctly.", 2, uut.getCount(testCard));
- assertEquals("Container reports wrong removed count.", 3, removed);
- }
-
- @Test
- public void cardRemoveCountIsEqualToCardCount() throws Exception {
- uut.addCard(testCard, 5);
-
- int removed = uut.removeCard(testCard, 5);
-
- assertEquals("Card was not removed from container.", 0, uut.getCount(testCard));
- assertEquals("Container reports wrong removed count.", 5, removed);
- }
-
- @Test
- public void cardRemoveCountIsGreaterThanCardCount() throws Exception {
- uut.addCard(testCard, 3);
-
- int removed = uut.removeCard(testCard, 5);
-
- assertEquals("Card was not removed from container.", 0, uut.getCount(testCard));
- assertEquals("Container reports wrong removed count.", 3, removed);
- }
-
- /*
- * Edge cases
- */
- @Test
- public void removedCardIsNull() throws Exception {
- exception.expect(NullPointerException.class);
- uut.removeCard(null, 0);
- }
-
- @Test
- public void removedCardIsNotInCardbase() throws Exception {
- int removed = uut.removeCard(testCard, 1);
-
- assertEquals("Removed count should be 0.", 0, removed);
- }
-
- @Test
- public void removedCountIsLessThanZero() throws Exception {
- uut.addCard(testCard, 3);
-
- int removed = uut.removeCard(testCard, -4);
-
- assertEquals("Card count in container should be unchanged.", 3, uut.getCount(testCard));
- assertEquals("Container reports wrong removed count.", 0, removed);
- }
-}
diff --git a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java b/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java
deleted file mode 100644
index 2d44c10..0000000
--- a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package eu.equalparts.cardbase.cardstorage;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.lang.reflect.Field;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import eu.equalparts.cardbase.Cardbase;
-import eu.equalparts.cardbase.cards.Card;
-
-public class StandaloneCardContainerTest {
- private StandaloneCardContainer uut;
- private static Card testCard;
-
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- ObjectMapper mapper = new ObjectMapper();
- testCard = mapper.readValue(StandaloneCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class);
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- uut = new Cardbase();
- }
-
- /***********************************************************************************
- * StandaloneCardContainer should extend ReferenceCardContainer
- ***********************************************************************************/
- @Test
- public void classInherits() throws Exception {
- assertTrue("StandaloneCardContainer should be subclass of ReferenceCardContainer.", uut instanceof ReferenceCardContainer);
- }
-
- /***********************************************************************************
- * Adding card tests, happy path
- ***********************************************************************************/
- @Test
- public void newCardIsAdded() throws Exception {
- assertNull("Container should not contain the test card to begin with.", uut.getCard(testCard.setCode, testCard.number));
-
- uut.addCard(testCard, 1);
-
- assertEquals("Container should contain the test card once it is added.", testCard, uut.getCard(testCard.setCode, testCard.number));
- }
-
- @Test
- public void existingCardIsIncremented() throws Exception {
- uut.addCard(testCard, 2);
- uut.addCard(testCard, 4);
-
- Card addedCard = uut.getCard(testCard.setCode, testCard.number);
- assertNotNull("Card was not found in cardbase.", addedCard);
- assertEquals("Card count was not updated correctly.", 6, uut.getCount(addedCard));
- }
-
- /*
- * Edge cases
- */
- @Test
- public void cardAddedIsNull() throws Exception {
- exception.expect(NullPointerException.class);
- uut.addCard(null, 0);
- }
-
- /***********************************************************************************
- * Removing card tests, happy path
- ***********************************************************************************/
- @Test
- public void cardIsStillPresentIfRemoveCountIsLessThanCardCount() throws Exception {
- uut.addCard(testCard, 5);
-
- uut.removeCard(testCard, 3);
-
- assertEquals("Card is missing from container.", testCard, uut.getCard(testCard.setCode, testCard.number));
- }
-
- @Test
- public void cardIsRemovedIfRemoveCountIsEqualToCardCount() throws Exception {
- uut.addCard(testCard, 5);
-
- uut.removeCard(testCard, 5);
-
- assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
- }
-
- @Test
- public void cardIsRemovedIfRemoveCountIsGreaterThanCardCount() throws Exception {
- uut.addCard(testCard, 3);
-
- uut.removeCard(testCard, 5);
-
- assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
- }
-
- /*
- * Edge cases
- */
- @Test
- public void removedCardIsNull() throws Exception {
- exception.expect(NullPointerException.class);
- uut.removeCard(null, 0);
- }
-
- @Test
- public void removedCardIsNotInContainer() throws Exception {
- assertNull("Card is not initially missing from container.", uut.getCard(testCard.setCode, testCard.number));
-
- uut.removeCard(testCard, 1);
-
- assertNull("Card is not missing from container.", uut.getCard(testCard.setCode, testCard.number));
- }
-
- @Test
- public void removedCountIsLessThanZero() throws Exception {
- uut.addCard(testCard, 3);
-
- uut.removeCard(testCard, -4);
-
- assertEquals("Card should not be missing from container.", testCard, uut.getCard(testCard.setCode, testCard.number));
- }
-
- /***********************************************************************************
- * Card getter tests, happy path
- ***********************************************************************************/
- @Test
- public void correctCardIsReturnedByGetter() throws Exception {
- uut.addCard(testCard, 1);
-
- Card card = uut.getCard(testCard.setCode, testCard.number);
-
- for (Field field : Card.class.getFields()) {
- assertEquals("Field " + field.getName(), field.get(testCard), field.get(card));
- }
- }
-
- @Test
- public void correctCardCollectionIsReturnedByGetter() throws Exception {
- uut.addCard(testCard, 1);
-
- assertTrue("Not all cards were returned by the getter.", uut.getCards().contains(testCard));
- }
-
- @Test
- public void cardCollectionWhenContainerIsEmpty() throws Exception {
- assertEquals("Returned collection size should have been 0.", 0, uut.getCards().size());
- }
-
- @Test
- public void getCardIsNotInCardbase() throws Exception {
- assertNull("Method should have returned null", uut.getCard(testCard.setCode, testCard.number));
- }
-}