From 67a3ab837c6e62e8b070999ca8fed5877e22494f Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 16 Mar 2016 21:26:14 +0100 Subject: Tests almost passing --- test/eu/equalparts/cardbase/CardbaseTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/eu/equalparts/cardbase') diff --git a/test/eu/equalparts/cardbase/CardbaseTest.java b/test/eu/equalparts/cardbase/CardbaseTest.java index ec9494e..524c7b1 100644 --- a/test/eu/equalparts/cardbase/CardbaseTest.java +++ b/test/eu/equalparts/cardbase/CardbaseTest.java @@ -19,6 +19,7 @@ import org.junit.rules.TemporaryFolder; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.equalparts.cardbase.Cardbase; @@ -116,7 +117,7 @@ public class CardbaseTest { public void loadFileHasWrongStructure() throws Exception { File wrongStructure = tempFolder.newFile("wrongStructure.json"); try (FileWriter writer = new FileWriter(wrongStructure)) { - writer.write("{\"field1\":\"content\",\"field2\":50,\"list\":[10,20,30]}"); + writer.write("{\"field1\":\"content\",\"field2\":50,\"field3\":{\"subfield\":10},\"list\":[10,20,30]}"); } exception.expect(JsonMappingException.class); @@ -150,7 +151,7 @@ public class CardbaseTest { uut.writeCollection(testFile); uut = new Cardbase(testFile); - assertEquals("Cardbase should contain " + testCount + " cards.", testCount, uut.getCards().size()); + assertEquals("Cardbase should contain 1 card.", 1, uut.getCards().size()); Card card = uut.getCard("M15", "281"); assertNotNull("Cardbase should contain a Shivan Dragon.", card); assertEquals("Cardbase should contain " + testCount + " Shivan Dragon.", testCount, uut.getCount(card)); @@ -273,8 +274,10 @@ public class CardbaseTest { @Test public void correctCardCollectionIsReturnedByGetter() throws Exception { uut = new Cardbase(new File(getClass().getResource("/testbase.cb").getFile())); - Map cards = new ObjectMapper().readValue(getClass().getResourceAsStream("/testbase.cb"), new TypeReference>() {}); - + ObjectMapper mapper = new ObjectMapper(); + JsonNode rawFile = mapper.readTree(getClass().getResourceAsStream("/testbase.cb")); + Map cards = rawFile.get("cards").traverse(mapper).readValueAs(new TypeReference>() {}); + assertTrue("Not all cards were returned by the getter.", uut.getCards().containsAll(cards.values())); } -- cgit v1.2.3