diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-15 22:04:06 +0100 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-15 22:04:06 +0100 |
commit | f70899a487cf0cdc58b8f4e0efea98e8404766c8 (patch) | |
tree | 9d1df2575447bd9daa392d64d502401c53c9c6cd /test/eu/equalparts | |
parent | e36558c84c443b2236eb3dacd2e3f66981818232 (diff) |
Refactor is coming along, just need to sort out the new file structure now
Diffstat (limited to 'test/eu/equalparts')
-rw-r--r-- | test/eu/equalparts/cardbase/CardbaseSortTest.java | 11 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/CardbaseTest.java | 51 |
2 files changed, 27 insertions, 35 deletions
diff --git a/test/eu/equalparts/cardbase/CardbaseSortTest.java b/test/eu/equalparts/cardbase/CardbaseSortTest.java index e3a92ee..2dbb68e 100644 --- a/test/eu/equalparts/cardbase/CardbaseSortTest.java +++ b/test/eu/equalparts/cardbase/CardbaseSortTest.java @@ -1,5 +1,6 @@ package eu.equalparts.cardbase; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Collection; @@ -40,8 +41,9 @@ public class CardbaseSortTest { @Before public void setUp() throws Exception { uut = new Cardbase(); - for (Card card : testCards) { - uut.addCard(card, card.count); + int[] cardCounts = {1, 2, 3, 8, 1, 15, 1, 1}; + for (int i = 0; i < testCards.size(); i++) { + uut.addCard(testCards.get(i), cardCounts[i]); } } @@ -387,11 +389,10 @@ public class CardbaseSortTest { public void sortByCount() throws Exception { Collection<Card> sortedCards = uut.sort("count"); int i = 0; - Integer[] counts = {1, 1, 1, 1, 2, 3, 8, 15 }; + int[] counts = {1, 1, 1, 1, 2, 3, 8, 15 }; for (Card card : sortedCards) { - assertTrue(card.count + " should have been " + counts[i] + ", i = " + i, card.count.equals(counts[i])); + assertEquals(uut.getCount(card) + " should have been " + counts[i] + ", i = " + i, uut.getCount(card), counts[i]); i++; } } - } diff --git a/test/eu/equalparts/cardbase/CardbaseTest.java b/test/eu/equalparts/cardbase/CardbaseTest.java index 424befc..ec9494e 100644 --- a/test/eu/equalparts/cardbase/CardbaseTest.java +++ b/test/eu/equalparts/cardbase/CardbaseTest.java @@ -90,7 +90,7 @@ public class CardbaseTest { for (CardInfo ci : testCards) { Card card = uut.getCard(ci.setCode, ci.number); assertNotNull("Missing card, set " + ci.setCode + ", " + ci.number, card); - assertEquals("Wrong card count, set " + ci.setCode + ", " + ci.number, ci.count, card.count); + assertEquals("Wrong card count, set " + ci.setCode + ", " + ci.number, ci.count, (Integer) uut.getCount(card)); } } @@ -139,19 +139,21 @@ public class CardbaseTest { ***********************************************************************************/ @Test public void cardbaseIsSaved() throws Exception { + final int testCount = 5; + File testFile = tempFolder.newFile("saveTest.cb"); uut.writeCollection(testFile); uut = new Cardbase(testFile); assertEquals("Cardbase should contain no cards.", 0, uut.getCards().size()); - uut.addCard(testCard, testCard.count); + uut.addCard(testCard, testCount); uut.writeCollection(testFile); uut = new Cardbase(testFile); - assertEquals("Cardbase should contain one card.", 1, uut.getCards().size()); + assertEquals("Cardbase should contain " + testCount + " cards.", testCount, uut.getCards().size()); Card card = uut.getCard("M15", "281"); assertNotNull("Cardbase should contain a Shivan Dragon.", card); - assertEquals("Cardbase should contain only one Shivan Dragon.", new Integer(1), card.count); + assertEquals("Cardbase should contain " + testCount + " Shivan Dragon.", testCount, uut.getCount(card)); } /* @@ -176,7 +178,7 @@ public class CardbaseTest { ***********************************************************************************/ @Test public void newCardIsAdded() throws Exception { - uut.addCard(testCard, testCard.count); + uut.addCard(testCard, 1); Card addedCard = uut.getCard("M15", "281"); assertNotNull("Card was not found in cardbase.", addedCard); @@ -185,15 +187,12 @@ public class CardbaseTest { @Test public void existingCardIsIncremented() throws Exception { - Card shivanClone = testCard.clone(); - uut.addCard(shivanClone, shivanClone.count); - Card shivanClone2 = testCard.clone(); - shivanClone2.count = 2; - uut.addCard(shivanClone2, shivanClone2.count); + uut.addCard(testCard, 2); + uut.addCard(testCard, 4); Card addedCard = uut.getCard("M15", "281"); assertNotNull("Card was not found in cardbase.", addedCard); - assertEquals("Card count was not updated correctly.", new Integer(3), addedCard.count); + assertEquals("Card count was not updated correctly.", 6, uut.getCount(addedCard)); } /* @@ -210,39 +209,31 @@ public class CardbaseTest { ***********************************************************************************/ @Test public void cardRemoveCountIsLessThanCardCount() throws Exception { - Card shivanClone = testCard.clone(); - shivanClone.count = 5; - uut.addCard(shivanClone, shivanClone.count); + uut.addCard(testCard, 5); - int removed = uut.removeCard(testCard, testCard.count); + int removed = uut.removeCard(testCard, 3); Card removedCard = uut.getCard("M15", "281"); assertNotNull("Card was not found in cardbase.", removedCard); - assertEquals("Card count was not updated correctly.", new Integer(4), removedCard.count); - assertEquals("Cardbase reports wrong removed count.", 1, removed); + assertEquals("Card count was not updated correctly.", 2, uut.getCount(removedCard)); + assertEquals("Cardbase reports wrong removed count.", 3, removed); } @Test public void cardRemoveCountIsEqualToCardCount() throws Exception { - Card shivanClone = testCard.clone(); - uut.addCard(shivanClone, shivanClone.count); + uut.addCard(testCard, 5); - int removed = uut.removeCard(testCard, testCard.count); + int removed = uut.removeCard(testCard, 5); Card removedCard = uut.getCard("M15", "281"); assertNull("Card was not removed from cardbase.", removedCard); - assertEquals("Cardbase reports wrong removed count.", 1, removed); + assertEquals("Cardbase reports wrong removed count.", 5, removed); } @Test public void cardRemoveCountIsGreaterThanCardCount() throws Exception { - Card shivanClone = testCard.clone(); - shivanClone.count = 3; - uut.addCard(shivanClone, shivanClone.count); - - Card shivanClone2 = testCard.clone(); - shivanClone2.count = 5; - int removed = uut.removeCard(shivanClone2, shivanClone2.count); + uut.addCard(testCard, 3); + int removed = uut.removeCard(testCard, 5); Card removedCard = uut.getCard("M15", "281"); assertNull("Card was not removed from cardbase.", removedCard); @@ -260,7 +251,7 @@ public class CardbaseTest { @Test public void removedCardIsNotInCardbase() throws Exception { - int removed = uut.removeCard(testCard, testCard.count); + int removed = uut.removeCard(testCard, 1); assertEquals("Removed count should be 0.", 0, removed); } @@ -270,7 +261,7 @@ public class CardbaseTest { ***********************************************************************************/ @Test public void correctCardIsReturnedByGetter() throws Exception { - uut.addCard(testCard.clone(), testCard.count); + uut.addCard(testCard, 1); Card card = uut.getCard("M15", "281"); |