From 85cf0f33a0ea071548b0cfa09c67473ceaf3e21b Mon Sep 17 00:00:00 2001 From: lwang Date: Thu, 25 Nov 2021 20:28:22 +0800 Subject: [PATCH] move unit test into JacksonParserTest --- .../java/org/jsfr/json/JacksonParserTest.java | 15 ++++- .../jsfr/json/JacksonResumableParserTest.java | 55 ------------------- .../test/resources/sample_big_integer.json | 1 + 3 files changed, 15 insertions(+), 56 deletions(-) delete mode 100644 jsurfer-all/src/test/java/org/jsfr/json/JacksonResumableParserTest.java create mode 100644 jsurfer-all/src/test/resources/sample_big_integer.json diff --git a/jsurfer-all/src/test/java/org/jsfr/json/JacksonParserTest.java b/jsurfer-all/src/test/java/org/jsfr/json/JacksonParserTest.java index 5328007..2403379 100644 --- a/jsurfer-all/src/test/java/org/jsfr/json/JacksonParserTest.java +++ b/jsurfer-all/src/test/java/org/jsfr/json/JacksonParserTest.java @@ -39,11 +39,15 @@ import org.junit.Test; import java.io.ByteArrayInputStream; +import java.math.BigInteger; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * Created by Leo on 2015/3/30. @@ -135,4 +139,13 @@ public void testAvroParser() throws Exception { verify(mockListener).onValue(eq(provider.primitive("foo")), any(ParsingContext.class)); } + @Test + public void testParsingLongIntegers() throws Exception { + Collector collector = surfer.collector(read("sample_big_integer.json")); + ValueBox box = collector.collectOne("$.value"); + collector.exec(); + BigInteger expected = new BigInteger("3452453534534534534543534543545"); + assertEquals(expected, box.get()); + } + } diff --git a/jsurfer-all/src/test/java/org/jsfr/json/JacksonResumableParserTest.java b/jsurfer-all/src/test/java/org/jsfr/json/JacksonResumableParserTest.java deleted file mode 100644 index 05750af..0000000 --- a/jsurfer-all/src/test/java/org/jsfr/json/JacksonResumableParserTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2015 WANG Lingsong - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.jsfr.json; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.jsfr.json.compiler.JsonPathCompiler; -import org.jsfr.json.path.JsonPath; -import org.jsfr.json.provider.JacksonProvider; -import org.junit.Before; -import org.junit.Test; - -import java.math.BigInteger; -import java.util.Iterator; - -import static org.junit.Assert.assertEquals; - -public class JacksonResumableParserTest extends JsonSurferTest { - - @Before - public void setUp() { - provider = new JacksonProvider(); - surfer = new JsonSurfer(JacksonParser.INSTANCE, provider); - } - - @Test - public void testParsingLongIntegers() { - BigInteger expected = new BigInteger("3452453534534534534543534543545"); - JsonPath jsonPath = JsonPathCompiler.compile("$"); - Iterator iterator = surfer.iterator("{\"value\": " + expected.toString() + "}", jsonPath); - Object parsedResult = iterator.next(); - assertEquals(0, ((ObjectNode) parsedResult).get("value").bigIntegerValue().compareTo(expected)); - } -} diff --git a/jsurfer-all/src/test/resources/sample_big_integer.json b/jsurfer-all/src/test/resources/sample_big_integer.json new file mode 100644 index 0000000..355a415 --- /dev/null +++ b/jsurfer-all/src/test/resources/sample_big_integer.json @@ -0,0 +1 @@ +{"value": 3452453534534534534543534543545} \ No newline at end of file