diff options
Diffstat (limited to 'test')
5 files changed, 59 insertions, 81 deletions
diff --git a/test/eu/equalparts/cardbase/CardbaseTest.java b/test/eu/equalparts/cardbase/CardbaseTest.java index 832880a..12c4842 100644 --- a/test/eu/equalparts/cardbase/CardbaseTest.java +++ b/test/eu/equalparts/cardbase/CardbaseTest.java @@ -17,9 +17,9 @@ import org.junit.rules.TemporaryFolder; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.card.Card; +import eu.equalparts.cardbase.json.JSON; /** * TODO deck functionality needs to be built into these. @@ -40,8 +40,7 @@ public class CardbaseTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - testCard = mapper.readValue(CardbaseTest.class.getResourceAsStream("/shivandragon.json"), Card.class); + testCard = JSON.mapper.readValue(CardbaseTest.class.getResourceAsStream("/shivandragon.json"), Card.class); } @AfterClass diff --git a/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java b/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java index 849d84c..2941e45 100644 --- a/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java +++ b/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java @@ -9,9 +9,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import com.fasterxml.jackson.databind.ObjectMapper; - -import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.card.Card; +import eu.equalparts.cardbase.json.JSON; public class ReferenceCardContainerTest { @@ -26,8 +25,7 @@ public class ReferenceCardContainerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - testCard = mapper.readValue(ReferenceCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); + testCard = JSON.mapper.readValue(ReferenceCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); } @Before diff --git a/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java index 6e9b31a..c420ee1 100644 --- a/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java +++ b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java @@ -14,9 +14,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import com.fasterxml.jackson.databind.ObjectMapper; - -import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.card.Card; +import eu.equalparts.cardbase.json.JSON; public class StandaloneCardContainerTest { private StandaloneCardContainer uut; @@ -30,8 +29,7 @@ public class StandaloneCardContainerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - testCard = mapper.readValue(StandaloneCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); + testCard = JSON.mapper.readValue(StandaloneCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); } @Before @@ -44,11 +42,11 @@ public class StandaloneCardContainerTest { ***********************************************************************************/ @Test public void newCardIsAdded() throws Exception { - assertNull("Container should not contain the test card to begin with.", uut.getCard(testCard.setCode, testCard.number)); + assertNull("Container should not contain the test card to begin with.", uut.getCard(testCard.setCode.get(), testCard.number.get())); 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 contain the test card once it is added.", testCard, uut.getCard(testCard.setCode.get(), testCard.number.get())); assertEquals("Container should have contained 1 test card.", 1, uut.getCount(testCard)); } @@ -57,7 +55,7 @@ public class StandaloneCardContainerTest { uut.addCard(testCard, 2); uut.addCard(testCard, 4); - Card addedCard = uut.getCard(testCard.setCode, testCard.number); + Card addedCard = uut.getCard(testCard.setCode.get(), testCard.number.get()); assertNotNull("Card was not found in cardbase.", addedCard); assertEquals("Card count was not updated correctly.", 6, uut.getCount(addedCard)); } @@ -82,7 +80,7 @@ public class StandaloneCardContainerTest { 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)); + assertEquals("Card is missing from container.", testCard, uut.getCard(testCard.setCode.get(), testCard.number.get())); } @Test @@ -93,7 +91,7 @@ public class StandaloneCardContainerTest { 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)); + assertNull("Card is not missing from container.", uut.getCard(testCard.setCode.get(), testCard.number.get())); } @Test @@ -104,7 +102,7 @@ public class StandaloneCardContainerTest { 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)); + assertNull("Card is not missing from container.", uut.getCard(testCard.setCode.get(), testCard.number.get())); } /* @@ -118,12 +116,12 @@ public class StandaloneCardContainerTest { @Test public void removedCardIsNotInContainer() throws Exception { - assertNull("Card is not initially missing from container.", uut.getCard(testCard.setCode, testCard.number)); + assertNull("Card is not initially missing from container.", uut.getCard(testCard.setCode.get(), testCard.number.get())); 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)); + assertNull("Card is not missing from container.", uut.getCard(testCard.setCode.get(), testCard.number.get())); } @Test @@ -134,7 +132,7 @@ public class StandaloneCardContainerTest { 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)); + assertEquals("Card should not be missing from container.", testCard, uut.getCard(testCard.setCode.get(), testCard.number.get())); } /*********************************************************************************** @@ -144,7 +142,7 @@ public class StandaloneCardContainerTest { public void correctCardIsReturnedByGetter() throws Exception { uut.addCard(testCard, 1); - Card card = uut.getCard(testCard.setCode, testCard.number); + Card card = uut.getCard(testCard.setCode.get(), testCard.number.get()); for (Field field : Card.class.getFields()) { assertEquals("Field " + field.getName(), field.get(testCard), field.get(card)); @@ -165,6 +163,6 @@ public class StandaloneCardContainerTest { @Test public void getCardIsNotInCardbase() throws Exception { - assertNull("Method should have returned null", uut.getCard(testCard.setCode, testCard.number)); + assertNull("Method should have returned null", uut.getCard(testCard.setCode.get(), testCard.number.get())); } } diff --git a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java index 4f5579d..c2ea71c 100644 --- a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java +++ b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java @@ -13,10 +13,10 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.equalparts.cardbase.cards.Card; -import eu.equalparts.cardbase.filtering.CardFiltering.FilterType; +import eu.equalparts.cardbase.card.Card; +import eu.equalparts.cardbase.filtering.CardFiltering.Filter; +import eu.equalparts.cardbase.json.JSON; public class CardFilteringTest { private static List<Card> allTestCards, testCards; @@ -26,8 +26,7 @@ public class CardFilteringTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - allTestCards = mapper.readValue(CardFilteringTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {}); + allTestCards = JSON.mapper.readValue(CardFilteringTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {}); } @Before @@ -37,7 +36,7 @@ public class CardFilteringTest { @Test public void filterByNameEquals() throws Exception { - CardFiltering.filterByField(testCards, "name", FilterType.EQUALS, "Callow jushi"); + CardFiltering.filterByField(testCards, "name", Filter.EQUALS, "Callow jushi"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name); @@ -45,7 +44,7 @@ public class CardFilteringTest { @Test public void filterByNameContains() throws Exception { - CardFiltering.filterByField(testCards, "name", FilterType.CONTAINS, "sh"); + CardFiltering.filterByField(testCards, "name", Filter.CONTAINS, "sh"); assertEquals("Wrong list size.", 3, testCards.size()); int i = 0; @@ -55,14 +54,14 @@ public class CardFilteringTest { "Disrupting Shoal", }; for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); i++; } } @Test public void filterByNameRegex() throws Exception { - CardFiltering.filterByField(testCards, "name", FilterType.REGEX, ".+?n"); + CardFiltering.filterByField(testCards, "name", Filter.REGEX, ".+?n"); assertEquals("Wrong list size.", 2, testCards.size()); int i = 0; @@ -71,14 +70,14 @@ public class CardFilteringTest { "Shivan Dragon", }; for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); i++; } } @Test public void filterByLayoutEquals() throws Exception { - CardFiltering.filterByField(testCards, "layout", FilterType.EQUALS, "flip"); + CardFiltering.filterByField(testCards, "layout", Filter.EQUALS, "flip"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name); @@ -86,7 +85,7 @@ public class CardFilteringTest { @Test public void filterByLayoutContains() throws Exception { - CardFiltering.filterByField(testCards, "layout", FilterType.CONTAINS, "l"); + CardFiltering.filterByField(testCards, "layout", Filter.CONTAINS, "l"); assertEquals("Wrong list size.", 8, testCards.size()); int i = 0; @@ -101,14 +100,14 @@ public class CardFilteringTest { "Ugin's Construct", }; for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); i++; } } @Test public void filterByLayoutRegex() throws Exception { - CardFiltering.filterByField(testCards, "layout", FilterType.REGEX, "fl[a-z]p"); + CardFiltering.filterByField(testCards, "layout", Filter.REGEX, "fl[a-z]p"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name); @@ -116,7 +115,7 @@ public class CardFilteringTest { @Test public void filterByManaCostEquals() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", FilterType.EQUALS, "{X}{U}{U}"); + CardFiltering.filterByField(testCards, "manaCost", Filter.EQUALS, "{X}{U}{U}"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Disrupting Shoal", testCards.get(0).name); @@ -124,7 +123,7 @@ public class CardFilteringTest { @Test public void filterByManaCostContains() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", FilterType.CONTAINS, "B"); + CardFiltering.filterByField(testCards, "manaCost", Filter.CONTAINS, "B"); assertEquals("Wrong list size.", 3, testCards.size()); int i = 0; @@ -134,14 +133,14 @@ public class CardFilteringTest { "Sorin Markov", }; for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); i++; } } @Test public void filterByManaCostRegex() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", FilterType.REGEX, "(\\{G\\}){8}"); + CardFiltering.filterByField(testCards, "manaCost", Filter.REGEX, "(\\{G\\}){8}"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Khalni Hydra", testCards.get(0).name); @@ -149,7 +148,7 @@ public class CardFilteringTest { @Test public void filterByCMCEquals() throws Exception { - CardFiltering.filterByField(testCards, "cmc", FilterType.EQUALS, "5"); + CardFiltering.filterByField(testCards, "cmc", Filter.EQUALS, "5"); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Coerced Confession", testCards.get(0).name); @@ -157,27 +156,12 @@ public class CardFilteringTest { @Test public void filterByCMCContains() throws Exception { - CardFiltering.filterByField(testCards, "cmc", FilterType.CONTAINS, "B"); - assertEquals("Wrong list size.", 3, testCards.size()); - int i = 0; - String[] names = { - "Coerced Confession", - "Nightmare", - "Sorin Markov", - }; - for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); - i++; - } } @Test public void filterByCMCRegex() throws Exception { - CardFiltering.filterByField(testCards, "cmc", FilterType.REGEX, "(\\{G\\}){8}"); - assertEquals("Wrong list size.", 1, testCards.size()); - assertEquals("Khalni Hydra", testCards.get(0).name); } @Test diff --git a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java index 4ec0f5e..04cf20d 100644 --- a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java +++ b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java @@ -10,9 +10,9 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.card.Card; +import eu.equalparts.cardbase.json.JSON; /** * Tests the sorting functionality. @@ -28,8 +28,7 @@ public class CardSortingTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - testCards = mapper.readValue(CardSortingTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {}); + testCards = JSON.mapper.readValue(CardSortingTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {}); } @Test @@ -47,7 +46,7 @@ public class CardSortingTest { "Ugin's Construct", }; for (Card card : testCards) { - assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); i++; } } @@ -67,7 +66,7 @@ public class CardSortingTest { "normal", }; for (Card card : testCards) { - assertTrue(card.layout + " should have been " + layouts[i] + ", i = " + i, card.layout.equals(layouts[i])); + assertTrue(card.layout.get() + " should have been " + layouts[i] + ", i = " + i, card.layout.get().equals(layouts[i])); i++; } } @@ -87,7 +86,7 @@ public class CardSortingTest { "{X}{U}{U}", }; for (Card card : testCards) { - assertTrue(card.manaCost + " should have been " + costs[i] + ", i = " + i, card.manaCost.equals(costs[i])); + assertTrue(card.manaCost.get() + " should have been " + costs[i] + ", i = " + i, card.manaCost.get().equals(costs[i])); i++; } } @@ -98,7 +97,7 @@ public class CardSortingTest { int i = 0; Integer[] cmcs = {2, 3, 4, 5, 6, 6, 6, 8}; for (Card card : testCards) { - assertTrue(card.cmc + " should have been " + cmcs[i] + ", i = " + i, card.cmc.equals(cmcs[i])); + assertTrue(card.cmc.get() + " should have been " + cmcs[i] + ", i = " + i, card.cmc.get().equals(cmcs[i])); i++; } } @@ -118,7 +117,7 @@ public class CardSortingTest { "Sorcery", }; for (Card card : testCards) { - assertTrue(card.type + " should have been " + types[i] + ", i = " + i, card.type.equals(types[i])); + assertTrue(card.type.get() + " should have been " + types[i] + ", i = " + i, card.type.get().equals(types[i])); i++; } } @@ -138,7 +137,7 @@ public class CardSortingTest { "Mythic Rare", }; for (Card card : testCards) { - assertTrue(card.rarity + " should have been " + rarities[i] + ", i = " + i, card.rarity.equals(rarities[i])); + assertTrue(card.rarity.get() + " should have been " + rarities[i] + ", i = " + i, card.rarity.get().equals(rarities[i])); i++; } } @@ -158,7 +157,7 @@ public class CardSortingTest { "You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.\nCounter target spell if its converted mana cost is X.", }; for (Card card : testCards) { - assertTrue(card.text + " should have been " + texts[i] + ", i = " + i, card.text.equals(texts[i])); + assertTrue(card.text.get() + " should have been " + texts[i] + ", i = " + i, card.text.get().equals(texts[i])); i++; } } @@ -178,7 +177,7 @@ public class CardSortingTest { "While trapping the Eldrazi on Zendikar, Ugin learned little from Sorin, but he gleaned the rudiments of lithomancy from Nahiri.", }; for (Card card : testCards) { - String flavor = card.flavor != null ? card.flavor : ""; + String flavor = card.flavor.get() != null ? card.flavor.get() : ""; assertTrue(flavor + " should have been " + flavors[i] + ", i = " + i, flavor.equals(flavors[i])); i++; } @@ -199,7 +198,7 @@ public class CardSortingTest { "Vance Kovacs", }; for (Card card : testCards) { - assertTrue(card.artist + " should have been " + artists[i] + ", i = " + i, card.artist.equals(artists[i])); + assertTrue(card.artist.get() + " should have been " + artists[i] + ", i = " + i, card.artist.get().equals(artists[i])); i++; } } @@ -219,7 +218,7 @@ public class CardSortingTest { "281", }; for (Card card : testCards) { - assertTrue(card.number + " should have been " + numbers[i] + ", i = " + i, card.number.equals(numbers[i])); + assertTrue(card.number.get() + " should have been " + numbers[i] + ", i = " + i, card.number.get().equals(numbers[i])); i++; } } @@ -239,7 +238,7 @@ public class CardSortingTest { "8", }; for (Card card : testCards) { - String power = card.power != null ? card.power : ""; + String power = card.power.get() != null ? card.power.get() : ""; assertTrue(power + " should have been " + powers[i] + ", i = " + i, power.equals(powers[i])); i++; } @@ -260,7 +259,7 @@ public class CardSortingTest { "8", }; for (Card card : testCards) { - String toughness = card.toughness != null ? card.toughness : ""; + String toughness = card.toughness.get() != null ? card.toughness.get() : ""; assertTrue(toughness + " should have been " + toughnesses[i] + ", i = " + i, toughness.equals(toughnesses[i])); i++; } @@ -272,7 +271,7 @@ public class CardSortingTest { int i = 0; Integer[] loyalties = {0, 0, 0, 0, 0, 0, 0, 4}; for (Card card : testCards) { - Integer loyalty = card.loyalty != null ? card.loyalty : 0; + Integer loyalty = card.loyalty.get() != null ? card.loyalty.get() : 0; assertTrue(loyalty + " should have been " + loyalties[i] + ", i = " + i, loyalty.equals(loyalties[i])); i++; } @@ -284,7 +283,7 @@ public class CardSortingTest { int i = 0; Integer[] ids = {74128, 74489, 193551, 238330, 366408, 383168, 383172, 391949 }; for (Card card : testCards) { - Integer id = card.multiverseid != null ? card.multiverseid : 0; + Integer id = card.multiverseid.get() != null ? card.multiverseid.get() : 0; assertTrue(id + " should have been " + ids[i] + ", i = " + i, id.equals(ids[i])); i++; } @@ -305,7 +304,7 @@ public class CardSortingTest { "ugin's construct", }; for (Card card : testCards) { - assertTrue(card.imageName + " should have been " + names[i] + ", i = " + i, card.imageName.equals(names[i])); + assertTrue(card.imageName.get() + " should have been " + names[i] + ", i = " + i, card.imageName.get().equals(names[i])); i++; } } @@ -325,7 +324,7 @@ public class CardSortingTest { "Dimir", }; for (Card card : testCards) { - String watermark = card.watermark != null ? card.watermark : ""; + String watermark = card.watermark.get() != null ? card.watermark.get() : ""; assertTrue(watermark + " should have been " + watermarks[i] + ", i = " + i, watermark.equals(watermarks[i])); i++; } @@ -346,7 +345,7 @@ public class CardSortingTest { "ROE", }; for (Card card : testCards) { - assertTrue(card.setCode + " should have been " + sets[i] + ", i = " + i, card.setCode.equals(sets[i])); + assertTrue(card.setCode.get() + " should have been " + sets[i] + ", i = " + i, card.setCode.get().equals(sets[i])); i++; } } @@ -366,7 +365,7 @@ public class CardSortingTest { "roe", }; for (Card card : testCards) { - assertTrue(card.imageCode + " should have been " + codes[i] + ", i = " + i, card.imageCode.equals(codes[i])); + assertTrue(card.imageCode.get() + " should have been " + codes[i] + ", i = " + i, card.imageCode.get().equals(codes[i])); i++; } } |