From: Kai Moritz Date: Wed, 22 Jun 2016 08:34:11 +0000 (+0200) Subject: Implement test-cases to test the handling of empty input X-Git-Tag: simple-mapper-1.0.0~38 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=dfdc6b81bce02386de2b4f6497ef78f15263c05d;p=simple-mapper Implement test-cases to test the handling of empty input --- diff --git a/src/test/java/de/juplo/jackson/SimpleMapperTest.java b/src/test/java/de/juplo/jackson/SimpleMapperTest.java new file mode 100644 index 0000000..075acca --- /dev/null +++ b/src/test/java/de/juplo/jackson/SimpleMapperTest.java @@ -0,0 +1,168 @@ +package de.juplo.jackson; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Spliterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import org.junit.Test; + + +/** + * + * @author Kai Moritz + */ +public class SimpleMapperTest +{ + private final JsonFactory factory = new JsonFactory(); + + + @Test + public void testConvertEmptyInputToArraySpliterator() throws Exception + { + Spliterator spliterator; + + spliterator = SimpleMapper.getArraySpliterator(get("/empty/1.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Object t) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getArraySpliterator(get("/empty/2.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Object t) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getArraySpliterator(get("/empty/3.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Object t) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getArraySpliterator(get("/empty/4.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Object t) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getArraySpliterator(get("/empty/5.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Object t) -> + { + fail("The consumer should never be called!"); + })); + } + + @Test + public void testConvertEmptyInputToList() throws Exception + { + List list; + + list = SimpleMapper.convertArray(get("/empty/1.json")); + assertEquals(0, list.size()); + list = SimpleMapper.convertArray(get("/empty/2.json")); + assertEquals(0, list.size()); + list = SimpleMapper.convertArray(get("/empty/3.json")); + assertEquals(0, list.size()); + list = SimpleMapper.convertArray(get("/empty/4.json")); + assertEquals(0, list.size()); + list = SimpleMapper.convertArray(get("/empty/5.json")); + assertEquals(0, list.size()); + } + + @Test + public void testConvertEmptyInputToObjectSpliterator() throws Exception + { + Spliterator> spliterator; + + spliterator = SimpleMapper.getObjectSpliterator(get("/empty/1.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getObjectSpliterator(get("/empty/2.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getObjectSpliterator(get("/empty/3.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getObjectSpliterator(get("/empty/4.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + spliterator = SimpleMapper.getObjectSpliterator(get("/empty/5.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + } + + @Test + public void testConvertEmptyInputToMap() throws Exception + { + Map map; + + map = SimpleMapper.convertObject(get("/empty/1.json")); + assertEquals(0, map.size()); + map = SimpleMapper.convertObject(get("/empty/2.json")); + assertEquals(0, map.size()); + map = SimpleMapper.convertObject(get("/empty/3.json")); + assertEquals(0, map.size()); + map = SimpleMapper.convertObject(get("/empty/4.json")); + assertEquals(0, map.size()); + map = SimpleMapper.convertObject(get("/empty/5.json")); + assertEquals(0, map.size()); + } + + @Test + public void testConvertEmptyInput() throws Exception + { + Object object; + + object = SimpleMapper.convert(get("/empty/1.json")); + assertNull(object); + object = SimpleMapper.convert(get("/empty/2.json")); + assertNull(object); + object = SimpleMapper.convert(get("/empty/3.json")); + assertNull(object); + object = SimpleMapper.convert(get("/empty/4.json")); + assertNull(object); + object = SimpleMapper.convert(get("/empty/5.json")); + assertNull(object); + } + + + private JsonParser get(String resource) throws IOException + { + InputStream is = SimpleMapperTest.class.getResourceAsStream(resource); + return factory.createParser(is); + } +} diff --git a/src/test/resources/empty/1.json b/src/test/resources/empty/1.json new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/empty/2.json b/src/test/resources/empty/2.json new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/test/resources/empty/2.json @@ -0,0 +1 @@ + diff --git a/src/test/resources/empty/3.json b/src/test/resources/empty/3.json new file mode 100644 index 0000000..09c0ba9 --- /dev/null +++ b/src/test/resources/empty/3.json @@ -0,0 +1 @@ + diff --git a/src/test/resources/empty/4.json b/src/test/resources/empty/4.json new file mode 100644 index 0000000..139597f --- /dev/null +++ b/src/test/resources/empty/4.json @@ -0,0 +1,2 @@ + + diff --git a/src/test/resources/empty/5.json b/src/test/resources/empty/5.json new file mode 100644 index 0000000..7bec3e6 --- /dev/null +++ b/src/test/resources/empty/5.json @@ -0,0 +1,7 @@ + + + + + + +