diff options
Diffstat (limited to 'test/eu/equalparts')
5 files changed, 410 insertions, 62 deletions
diff --git a/test/eu/equalparts/cardbase/CardbaseTest.java b/test/eu/equalparts/cardbase/CardbaseTest.java index 12c4842..f9ca0d8 100644 --- a/test/eu/equalparts/cardbase/CardbaseTest.java +++ b/test/eu/equalparts/cardbase/CardbaseTest.java @@ -184,8 +184,5 @@ public class CardbaseTest { /*********************************************************************************** * Deck tests ***********************************************************************************/ - @Test - public void test() throws Exception { - - } + } diff --git a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java index 9a98469..87755db 100644 --- a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java +++ b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java @@ -860,6 +860,36 @@ public class CardbaseCLITest { assertEquals("Please select a set before removing cards." + EOL, testOutput.toString()); } + @Test + public void removeIntegerOverflowAmount() throws Exception { + uut = new CardbaseCLI(TEST_REMOTE, path("/testbase.cb")); + uut.interpretInput("set FRF"); + + try { + System.setOut(new PrintStream(testOutput)); + uut.interpretInput("remove 129 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); + } finally { + System.setOut(console); + } + + assertEquals("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 is not a valid number of cards." + EOL, testOutput.toString()); + } + + @Test + public void removeNonIntAmount() throws Exception { + uut = new CardbaseCLI(TEST_REMOTE, path("/testbase.cb")); + uut.interpretInput("set FRF"); + + try { + System.setOut(new PrintStream(testOutput)); + uut.interpretInput("remove 129 1OO"); + } finally { + System.setOut(console); + } + + assertEquals("1OO is not a valid number of cards." + EOL, testOutput.toString()); + } + /*********************************************************************************** * add() tests, happy path ***********************************************************************************/ @@ -1252,6 +1282,34 @@ public class CardbaseCLITest { assertEquals("Total: 0" + EOL, testOutput.toString()); } + @Test + public void addIntegerOverflowAmount() throws Exception { + uut.interpretInput("set FRF"); + + try { + System.setOut(new PrintStream(testOutput)); + uut.interpretInput("129 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); + } finally { + System.setOut(console); + } + + assertEquals("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 is not a valid number of cards." + EOL, testOutput.toString()); + } + + @Test + public void addNonIntAmount() throws Exception { + uut.interpretInput("set FRF"); + + try { + System.setOut(new PrintStream(testOutput)); + uut.interpretInput("129 1OO"); + } finally { + System.setOut(console); + } + + assertEquals("1OO is not a valid number of cards." + EOL, testOutput.toString()); + } + /*********************************************************************************** * undo() tests, happy path ***********************************************************************************/ diff --git a/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java index c420ee1..62f8dd7 100644 --- a/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java +++ b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java @@ -68,7 +68,7 @@ public class StandaloneCardContainerTest { exception.expect(NullPointerException.class); uut.addCard(null, 0); } - + /*********************************************************************************** * Removing card tests, happy path ***********************************************************************************/ diff --git a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java index 8e9d00b..ed3d3f2 100644 --- a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java +++ b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java @@ -15,7 +15,8 @@ import org.junit.rules.ExpectedException; import com.fasterxml.jackson.core.type.TypeReference; import eu.equalparts.cardbase.card.Card; -import eu.equalparts.cardbase.filtering.CardFiltering.Filter; +import eu.equalparts.cardbase.filtering.Filter; +import eu.equalparts.cardbase.filtering.Filter.FilterType; import eu.equalparts.cardbase.json.JSON; public class CardFilteringTest { @@ -34,9 +35,14 @@ public class CardFilteringTest { testCards = new LinkedList<>(allTestCards); } + /* + * Filter tests, happy path + */ @Test public void filterByNameEquals() throws Exception { - CardFiltering.filterByField(testCards, "name", Filter.EQUALS, "Callow jushi"); + Filter filter = new Filter(FilterType.EQUALS, "name", "Callow jushi"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name.get()); @@ -44,7 +50,9 @@ public class CardFilteringTest { @Test public void filterByNameContains() throws Exception { - CardFiltering.filterByField(testCards, "name", Filter.CONTAINS, "sh"); + Filter filter = new Filter(FilterType.CONTAINS, "name", "sh"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 3, testCards.size()); int i = 0; @@ -61,7 +69,9 @@ public class CardFilteringTest { @Test public void filterByNameRegex() throws Exception { - CardFiltering.filterByField(testCards, "name", Filter.REGEX, ".+?n"); + Filter filter = new Filter(FilterType.REGEX, "name", ".+?n"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 2, testCards.size()); int i = 0; @@ -77,29 +87,25 @@ public class CardFilteringTest { @Test public void filterByNameGreaterThan() throws Exception { - CardFiltering.filterByField(testCards, "name", Filter.GREATER_THAN, "5"); + Filter filter = new Filter(FilterType.GREATER_THAN, "name", "0"); + exception.expect(IllegalArgumentException.class); - assertEquals("Wrong list size.", 8, testCards.size()); - int i = 0; - String[] names = { - "Callow Jushi", - "Coerced Confession", - "Khalni Hydra", - "Nightmare", - "Shivan Dragon", - "Disrupting Shoal", - "Sorin Markov", - "Ugin's Construct", - }; - for (Card card : testCards) { - assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); - i++; - } + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByNameSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "name", "0"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); } @Test public void filterByLayoutEquals() throws Exception { - CardFiltering.filterByField(testCards, "layout", Filter.EQUALS, "flip"); + Filter filter = new Filter(FilterType.EQUALS, "layout", "flip"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name.get()); @@ -107,7 +113,9 @@ public class CardFilteringTest { @Test public void filterByLayoutContains() throws Exception { - CardFiltering.filterByField(testCards, "layout", Filter.CONTAINS, "l"); + Filter filter = new Filter(FilterType.CONTAINS, "layout", "l"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 8, testCards.size()); int i = 0; @@ -129,15 +137,35 @@ public class CardFilteringTest { @Test public void filterByLayoutRegex() throws Exception { - CardFiltering.filterByField(testCards, "layout", Filter.REGEX, "fl[a-z]p"); + Filter filter = new Filter(FilterType.REGEX, "layout", "fl[a-z]p"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Callow Jushi", testCards.get(0).name.get()); } @Test + public void filterByLayoutGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "layout", "5"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByLayoutSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.SMALLER_THAN, "layout", "5"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + + @Test public void filterByManaCostEquals() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", Filter.EQUALS, "{X}{U}{U}"); + Filter filter = new Filter(FilterType.EQUALS, "manaCost", "{X}{U}{U}"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Disrupting Shoal", testCards.get(0).name.get()); @@ -145,7 +173,9 @@ public class CardFilteringTest { @Test public void filterByManaCostContains() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", Filter.CONTAINS, "B"); + Filter filter = new Filter(FilterType.CONTAINS, "manaCost", "B"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 3, testCards.size()); int i = 0; @@ -162,15 +192,35 @@ public class CardFilteringTest { @Test public void filterByManaCostRegex() throws Exception { - CardFiltering.filterByField(testCards, "manaCost", Filter.REGEX, "(\\{G\\}){8}"); + Filter filter = new Filter(FilterType.REGEX, "manaCost", "(\\{G\\}){8}"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Khalni Hydra", testCards.get(0).name.get()); } @Test + public void filterByManaCostGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "manaCost", "5"); + + exception.expect(IllegalArgumentException.class); + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByManaCostSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "manaCost", "5"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + + @Test public void filterByCMCEquals() throws Exception { - CardFiltering.filterByField(testCards, "cmc", Filter.EQUALS, "5"); + Filter filter = new Filter(FilterType.EQUALS, "cmc", "5"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Coerced Confession", testCards.get(0).name.get()); @@ -178,7 +228,9 @@ public class CardFilteringTest { @Test public void filterByCMCContains() throws Exception { - CardFiltering.filterByField(testCards, "cmc", Filter.CONTAINS, "5"); + Filter filter = new Filter(FilterType.CONTAINS, "cmc", "5"); + + CardFiltering.filterByField(testCards, filter); assertEquals("Wrong list size.", 1, testCards.size()); assertEquals("Coerced Confession", testCards.get(0).name.get()); @@ -186,17 +238,194 @@ public class CardFilteringTest { @Test public void filterByCMCRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "cmc", "5"); + CardFiltering.filterByField(testCards, filter); } - + @Test - public void filterByType() throws Exception { - + public void filterByCMCGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "cmc", "5"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 4, testCards.size()); + int i = 0; + String[] names = { + "Khalni Hydra", + "Nightmare", + "Shivan Dragon", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByCMCSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.SMALLER_THAN, "cmc", "5"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Disrupting Shoal", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } } @Test - public void filterByRarity() throws Exception { + public void filterByTypeEquals() throws Exception { + Filter filter = new Filter(FilterType.EQUALS, "type", "Sorcery"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Coerced Confession", testCards.get(0).name.get()); + } + + @Test + public void filterByTypeContains() throws Exception { + Filter filter = new Filter(FilterType.CONTAINS, "type", "Creature"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 5, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Khalni Hydra", + "Nightmare", + "Shivan Dragon", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByTypeRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "type", "[^ ]+? —.*"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 6, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Khalni Hydra", + "Nightmare", + "Shivan Dragon", + "Disrupting Shoal", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByTypeGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "type", "0"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByTypeSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "name", "0"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + @Test + public void filterByRarityEquals() throws Exception { + Filter filter = new Filter(FilterType.EQUALS, "rarity", "Mythic Rare"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 2, testCards.size()); + int i = 0; + String[] names = { + "Khalni Hydra", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByRarityContains() throws Exception { + Filter filter = new Filter(FilterType.CONTAINS, "rarity", "Rare"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 5, testCards.size()); + int i = 0; + String[] names = { + "Khalni Hydra", + "Nightmare", + "Shivan Dragon", + "Disrupting Shoal", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByRarityRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "rarity", "[^ ]+"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 6, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Coerced Confession", + "Nightmare", + "Shivan Dragon", + "Disrupting Shoal", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByRarityGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "rarity", "0"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByRaritySmallerThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "rarity", "0"); + exception.expect(IllegalArgumentException.class); + + CardFiltering.filterByField(testCards, filter); } @Test @@ -245,12 +474,97 @@ public class CardFilteringTest { } @Test - public void filterByWatermark() throws Exception { + public void filterBySetCode() throws Exception { } + + /* + * Filter validation tests, happy path + */ + @Test + public void validateNameEqualsSomethingFilter() throws Exception { + Filter testFilter = new Filter(FilterType.EQUALS, "name", "Card name"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } @Test - public void filterBySetCode() throws Exception { - + public void validateFlavourEqualsNothingFilter() throws Exception { + Filter testFilter = new Filter(FilterType.EQUALS, "flavor", ""); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateTextContainsVigilanceFilter() throws Exception { + Filter testFilter = new Filter(FilterType.CONTAINS, "text", "vigilance"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateCMCContainsNumberFilter() throws Exception { + Filter testFilter = new Filter(FilterType.CONTAINS, "cmc", "5"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateTypeRegexFilter() throws Exception { + Filter testFilter = new Filter(FilterType.REGEX, "type", "Legendary [A-z]+? Creature.*"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateManaCostRegexFilter() throws Exception { + Filter testFilter = new Filter(FilterType.REGEX, "manaCost", ".*?{./.}.*?"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateCMCGreaterThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.GREATER_THAN, "cmc", "5"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validatePowerGreaterThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.GREATER_THAN, "power", "3"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateLoyaltySmallerThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.SMALLER_THAN, "loyalty", "3"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateToughnessSmallerThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.SMALLER_THAN, "toughness", "5"); + + assertTrue(CardFiltering.isFilterValid(testFilter)); + } + + /* + * Edge cases + */ + @Test + public void validateNonIntegerFieldGreaterThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.GREATER_THAN, "name", "5"); + + assertTrue(!CardFiltering.isFilterValid(testFilter)); + } + + @Test + public void validateNonIntegerValueGreaterThanFilter() throws Exception { + Filter testFilter = new Filter(FilterType.GREATER_THAN, "cmc", "test"); + + assertTrue(!CardFiltering.isFilterValid(testFilter)); } } diff --git a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java index 2e4f0e6..d576726 100644 --- a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java +++ b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java @@ -310,27 +310,6 @@ public class CardSortingTest { } @Test - public void sortByWatermark() throws Exception { - CardSorting.sortByField(testCards, "watermark"); - int i = 0; - String[] watermarks = { - "", - "", - "", - "", - "", - "", - "", - "Dimir", - }; - for (Card card : testCards) { - String watermark = card.watermark.get() != null ? card.watermark.get() : ""; - assertTrue(watermark + " should have been " + watermarks[i] + ", i = " + i, watermark.equals(watermarks[i])); - i++; - } - } - - @Test public void sortBySetCode() throws Exception { CardSorting.sortByField(testCards, "setCode"); int i = 0; |