From f065aecd3991c1b9f131aed202ef1573d36e9d4d Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 21 Jun 2016 19:34:17 +0200 Subject: [PATCH] WIP --- .../de/juplo/jackson/SimpleMapperTest.java | 110 ++++++++++++++++++ src/test/resources/empty/1.json | 0 src/test/resources/empty/2.json | 1 + src/test/resources/empty/3.json | 1 + src/test/resources/empty/4.json | 2 + src/test/resources/empty/5.json | 7 ++ 6 files changed, 121 insertions(+) create mode 100644 src/test/java/de/juplo/jackson/SimpleMapperTest.java create mode 100644 src/test/resources/empty/1.json create mode 100644 src/test/resources/empty/2.json create mode 100644 src/test/resources/empty/3.json create mode 100644 src/test/resources/empty/4.json create mode 100644 src/test/resources/empty/5.json 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..3178c89 --- /dev/null +++ b/src/test/java/de/juplo/jackson/SimpleMapperTest.java @@ -0,0 +1,110 @@ +package de.juplo.jackson; + +import com.fasterxml.jackson.core.JsonFactory; +import java.io.InputStream; +import java.util.Map.Entry; +import java.util.Spliterator; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; +import org.junit.Test; + + +/** + * + * @author Kai Moritz + */ +public class SimpleMapperTest +{ + private final SimpleMapper mapper = new SimpleMapper(new JsonFactory()); + + + @Test + public void testConvertEmptyArray() throws Exception + { + Spliterator spliterator; + + spliterator = mapper.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 = mapper.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 = mapper.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 = mapper.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 = mapper.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 testConvertEmptyObject() throws Exception + { + Spliterator> spliterator; + + spliterator = mapper.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 = mapper.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 = mapper.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 = mapper.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 = mapper.getObjectSpliterator(get("/empty/5.json")); + assertFalse( + "The created splitter should have no entries", + spliterator.tryAdvance((Entry e) -> + { + fail("The consumer should never be called!"); + })); + } + + + private InputStream get(String resource) + { + return SimpleMapperTest.class.getResourceAsStream(resource); + } +} 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 @@ + + + + + + + -- 2.20.1