From 3adc04bd13f9157b64c7459821429ca757fe1748 Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Thu, 5 Nov 2015 23:10:05 +0100 Subject: [PATCH] Made write features JsonProvider neutral. --- build.gradle | 1 - .../java/com/jayway/jsonpath/JsonPath.java | 18 ++++++++++++++-- .../com/jayway/jsonpath/ValueConverter.java | 21 +++++++++++++++++++ .../com/jayway/jsonpath/WriteContext.java | 6 +----- .../jayway/jsonpath/internal/JsonReader.java | 2 +- .../com/jayway/jsonpath/internal/PathRef.java | 16 +++++++------- .../jsonpath/internal/ValueConverter.java | 10 --------- .../{ => internal/function}/Function.java | 2 +- .../internal/function/FunctionFactory.java | 1 - .../jsonpath/internal/function/Length.java | 1 - .../internal/function/PassthruFunction.java | 1 - .../function/numeric/AbstractAggregation.java | 2 +- .../internal/token/FunctionPathToken.java | 2 +- .../jsonpath/internal/token/PathToken.java | 2 +- .../spi/json/AbstractJsonProvider.java | 8 +++---- .../java/com/jayway/jsonpath/BaseTest.java | 2 +- .../com/jayway/jsonpath/DeepScanTest.java | 7 +++---- .../jayway/jsonpath/GsonJsonProviderTest.java | 1 - .../com/jayway/jsonpath/InlineFilterTest.java | 5 ++--- .../com/jayway/jsonpath/JsonProviderTest.java | 3 --- .../com/jayway/jsonpath/MultiPropTest.java | 1 - .../java/com/jayway/jsonpath/WriteTest.java | 21 ++++++++++++------- .../functions/NumericFunctionTest.java | 11 ---------- .../jsonpath/internal/JsonReaderTest.java | 11 ++++------ .../internal/token/PathTokenTest.java | 9 ++------ 25 files changed, 80 insertions(+), 84 deletions(-) create mode 100644 json-path/src/main/java/com/jayway/jsonpath/ValueConverter.java delete mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/ValueConverter.java rename json-path/src/main/java/com/jayway/jsonpath/{ => internal/function}/Function.java (96%) diff --git a/build.gradle b/build.gradle index ebed1509..ec8aa0c7 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,6 @@ subprojects { apply plugin: 'java' apply plugin: 'signing' apply plugin: 'osgi' - apply plugin: 'maven' sourceCompatibility = 1.6 targetCompatibility = 1.6 diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index fb0ecdc5..bb35ab18 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -15,7 +15,12 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.internal.*; +import com.jayway.jsonpath.internal.EvaluationContext; +import com.jayway.jsonpath.internal.JsonReader; +import com.jayway.jsonpath.internal.Path; +import com.jayway.jsonpath.internal.PathCompiler; +import com.jayway.jsonpath.internal.PathRef; +import com.jayway.jsonpath.internal.Utils; import com.jayway.jsonpath.spi.json.JsonProvider; import java.io.File; @@ -221,9 +226,19 @@ public class JsonPath { return resultByConfiguration(jsonObject, configuration, evaluationContext); } + + /** + * Converts the value on the given path. + * + * @param jsonObject a json object + * @param valueConverter Converter object to be invoked + * @param configuration configuration to use + * @return the updated jsonObject or the path list to updated objects if option AS_PATH_LIST is set. + */ public T convert(Object jsonObject, ValueConverter valueConverter, Configuration configuration) { notNull(jsonObject, "json can not be null"); notNull(configuration, "configuration can not be null"); + notNull(valueConverter, "valueConverter can not be null"); EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true); for (PathRef updateOperation : evaluationContext.updateOperations()) { updateOperation.convert(valueConverter, configuration); @@ -231,7 +246,6 @@ public class JsonPath { return resultByConfiguration(jsonObject, configuration, evaluationContext); } - /** * Deletes the object this path points to in the provided jsonObject * diff --git a/json-path/src/main/java/com/jayway/jsonpath/ValueConverter.java b/json-path/src/main/java/com/jayway/jsonpath/ValueConverter.java new file mode 100644 index 00000000..75f39a2a --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/ValueConverter.java @@ -0,0 +1,21 @@ +/* + * Copyright 2011 the original author or authors. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jayway.jsonpath; + +public interface ValueConverter { + + public Object convert(Object currentValue, Configuration configuration); + +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/WriteContext.java b/json-path/src/main/java/com/jayway/jsonpath/WriteContext.java index 4c617a71..32fcc81c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/WriteContext.java +++ b/json-path/src/main/java/com/jayway/jsonpath/WriteContext.java @@ -14,8 +14,6 @@ */ package com.jayway.jsonpath; -import com.jayway.jsonpath.internal.ValueConverter; - public interface WriteContext { /** @@ -62,7 +60,7 @@ public interface WriteContext { * Converts the value on the given path. * * @param path path to be converted set - * @param valueConverter Converter object to be invoked (or lambda:)) + * @param valueConverter Converter object to be invoked * @param filters filters * @return a document context */ @@ -137,7 +135,6 @@ public interface WriteContext { */ DocumentContext put(String path, String key, Object value, Predicate... filters); - /** * Add or update the key with a the given value at the given path * @@ -168,5 +165,4 @@ public interface WriteContext { * @return a document content. */ DocumentContext renameKey(JsonPath path, String oldKeyName, String newKeyName); - } \ No newline at end of file diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java index fad5c6a1..4462a638 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java @@ -23,6 +23,7 @@ import com.jayway.jsonpath.ParseContext; import com.jayway.jsonpath.Predicate; import com.jayway.jsonpath.ReadContext; import com.jayway.jsonpath.TypeRef; +import com.jayway.jsonpath.ValueConverter; import com.jayway.jsonpath.spi.cache.Cache; import com.jayway.jsonpath.spi.cache.CacheProvider; import org.slf4j.Logger; @@ -36,7 +37,6 @@ import java.util.LinkedList; import java.util.List; import static com.jayway.jsonpath.JsonPath.compile; -import static com.jayway.jsonpath.JsonPath.parse; import static com.jayway.jsonpath.internal.Utils.notEmpty; import static com.jayway.jsonpath.internal.Utils.notNull; import static java.util.Arrays.asList; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java b/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java index 6a2031fb..c93742b8 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java @@ -1,10 +1,12 @@ package com.jayway.jsonpath.internal; -import com.jayway.jsonpath.*; +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.InvalidModificationException; +import com.jayway.jsonpath.PathNotFoundException; +import com.jayway.jsonpath.ValueConverter; import com.jayway.jsonpath.spi.json.JsonProvider; import java.util.Collection; -import java.util.List; public abstract class PathRef implements Comparable { @@ -149,12 +151,10 @@ public abstract class PathRef implements Comparable { private static class ArrayIndexPathRef extends PathRef { private int index; - private Object value; private ArrayIndexPathRef(Object parent, int index) { super(parent); this.index = index; - this.value = ((List) parent).get(index); } public void set(Object newVal, Configuration configuration){ @@ -163,11 +163,11 @@ public abstract class PathRef implements Comparable { public void convert(ValueConverter valueConverter, Configuration configuration){ Object currentValue = configuration.jsonProvider().getArrayIndex(parent, index); - configuration.jsonProvider().setArrayIndex(parent, index, valueConverter.convert(currentValue)); + configuration.jsonProvider().setArrayIndex(parent, index, valueConverter.convert(currentValue, configuration)); } public void delete(Configuration configuration){ - configuration.jsonProvider().removeProperty(parent, value); + configuration.jsonProvider().removeProperty(parent, index); } public void add(Object value, Configuration configuration){ @@ -236,7 +236,7 @@ public abstract class PathRef implements Comparable { @Override public void convert(ValueConverter valueConverter, Configuration configuration) { Object currentValue = configuration.jsonProvider().getMapValue(parent, property); - configuration.jsonProvider().setProperty(parent, property, valueConverter.convert(currentValue)); + configuration.jsonProvider().setProperty(parent, property, valueConverter.convert(currentValue, configuration)); } @@ -300,7 +300,7 @@ public abstract class PathRef implements Comparable { public void convert(ValueConverter valueConverter, Configuration configuration) { for (String property : properties) { Object currentValue = configuration.jsonProvider().getMapValue(parent, property); - configuration.jsonProvider().setProperty(parent, property, valueConverter.convert(currentValue)); + configuration.jsonProvider().setProperty(parent, property, valueConverter.convert(currentValue, configuration)); } } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/ValueConverter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/ValueConverter.java deleted file mode 100644 index ca2b31b3..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/ValueConverter.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.jayway.jsonpath.internal; - -/** - * Created by tom on 29/04/15. - */ -public interface ValueConverter { - - public Object convert(Object currentValue); - -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/Function.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Function.java similarity index 96% rename from json-path/src/main/java/com/jayway/jsonpath/Function.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/function/Function.java index 4256f8cf..a7dd2d16 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Function.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Function.java @@ -1,4 +1,4 @@ -package com.jayway.jsonpath; +package com.jayway.jsonpath.internal.function; import com.jayway.jsonpath.internal.EvaluationContext; import com.jayway.jsonpath.internal.PathRef; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/function/FunctionFactory.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/FunctionFactory.java index a03e72a3..755a54d6 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/function/FunctionFactory.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/FunctionFactory.java @@ -1,6 +1,5 @@ package com.jayway.jsonpath.internal.function; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.InvalidPathException; import com.jayway.jsonpath.internal.function.numeric.Average; import com.jayway.jsonpath.internal.function.numeric.Max; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java index 1fdf1278..e55410d1 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java @@ -1,6 +1,5 @@ package com.jayway.jsonpath.internal.function; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.internal.EvaluationContext; import com.jayway.jsonpath.internal.PathRef; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruFunction.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruFunction.java index fadda31d..0eb67a39 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruFunction.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruFunction.java @@ -1,6 +1,5 @@ package com.jayway.jsonpath.internal.function; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.internal.EvaluationContext; import com.jayway.jsonpath.internal.PathRef; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java index ddb2ad7d..e23d945f 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java @@ -1,8 +1,8 @@ package com.jayway.jsonpath.internal.function.numeric; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.internal.EvaluationContext; import com.jayway.jsonpath.internal.PathRef; +import com.jayway.jsonpath.internal.function.Function; /** * Defines the pattern for processing numerical values via an abstract implementation that iterates over the collection diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java index 68d15fcc..b2e152ef 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java @@ -1,7 +1,7 @@ package com.jayway.jsonpath.internal.token; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.internal.PathRef; +import com.jayway.jsonpath.internal.function.Function; import com.jayway.jsonpath.internal.function.FunctionFactory; import java.util.regex.Matcher; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java index d9bc9292..c504bb44 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java @@ -14,11 +14,11 @@ */ package com.jayway.jsonpath.internal.token; -import com.jayway.jsonpath.Function; import com.jayway.jsonpath.Option; import com.jayway.jsonpath.PathNotFoundException; import com.jayway.jsonpath.internal.PathRef; import com.jayway.jsonpath.internal.Utils; +import com.jayway.jsonpath.internal.function.Function; import com.jayway.jsonpath.spi.json.JsonProvider; import java.util.List; diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java index f95102e5..56cfb47c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java @@ -99,16 +99,16 @@ public abstract class AbstractJsonProvider implements JsonProvider { * Removes a value in an object or array * * @param obj an array or an object - * @param key a String key or an object in a Collection to be removed. + * @param key a String key or a numerical index to remove */ @SuppressWarnings("unchecked") public void removeProperty(Object obj, Object key) { if (isMap(obj)) ((Map) obj).remove(key.toString()); else { - Collection collection = (Collection) obj; - //int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); - collection.remove(key); + List list = (List) obj; + int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); + list.remove(index); } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java b/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java index b387f43a..cbbf6bd0 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java @@ -1,13 +1,13 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.Path; +import com.jayway.jsonpath.internal.token.PredicateContextImpl; import com.jayway.jsonpath.spi.json.GsonJsonProvider; import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider; import com.jayway.jsonpath.spi.json.JacksonJsonProvider; import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider; import com.jayway.jsonpath.spi.mapper.GsonMappingProvider; import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; -import com.jayway.jsonpath.internal.token.PredicateContextImpl; import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider; import java.util.HashMap; diff --git a/json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java b/json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java index 6724809e..faccd840 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java @@ -2,14 +2,13 @@ package com.jayway.jsonpath; import org.junit.Test; +import java.util.List; +import java.util.Map; + import static com.jayway.jsonpath.JsonPath.using; import static com.jayway.jsonpath.TestUtils.assertEvaluationThrows; - import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; -import java.util.Map; - /** * Deep scan is indefinite, so certain "illegal" actions become a no-op instead of a path evaluation exception. */ diff --git a/json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java index 08054810..8f3ec333 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java @@ -3,7 +3,6 @@ package com.jayway.jsonpath; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; import com.jayway.jsonpath.spi.mapper.MappingException; import org.junit.Test; diff --git a/json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java index d734a513..7fed35d1 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java @@ -1,13 +1,12 @@ package com.jayway.jsonpath; -import static com.jayway.jsonpath.TestUtils.assertHasNoResults; -import static com.jayway.jsonpath.TestUtils.assertHasOneResult; - import org.junit.Test; import java.util.ArrayList; import java.util.List; +import static com.jayway.jsonpath.TestUtils.assertHasNoResults; +import static com.jayway.jsonpath.TestUtils.assertHasOneResult; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java index 2949fcaa..00f7513a 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java @@ -4,9 +4,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.io.IOException; -import java.util.List; - import static com.jayway.jsonpath.JsonPath.using; import static org.assertj.core.api.Assertions.assertThat; diff --git a/json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java b/json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java index 2f7d45d7..fc5567a8 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java @@ -7,7 +7,6 @@ import java.util.Map; import static com.jayway.jsonpath.JsonPath.using; import static com.jayway.jsonpath.TestUtils.assertEvaluationThrows; - import static org.assertj.core.api.Assertions.assertThat; public class MultiPropTest { diff --git a/json-path/src/test/java/com/jayway/jsonpath/WriteTest.java b/json-path/src/test/java/com/jayway/jsonpath/WriteTest.java index aa4e2446..e06f062d 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/WriteTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/WriteTest.java @@ -1,9 +1,12 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.internal.ValueConverter; import org.junit.Test; -import java.util.*; +import java.io.InputStream; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import static com.jayway.jsonpath.JsonPath.parse; import static java.util.Collections.emptyMap; @@ -126,8 +129,9 @@ public class WriteTest extends BaseTest { @Test public void an_array_criteria_with_multiple_results_can_be_deleted(){ + InputStream stream = this.getClass().getResourceAsStream("/json_array_multiple_delete.json"); String deletePath = "$._embedded.mandates[?(@.count=~/0/)]"; - DocumentContext documentContext = JsonPath.parse(getClass().getResourceAsStream("/json_array_multiple_delete.json")); + DocumentContext documentContext = JsonPath.parse(stream); documentContext.delete(deletePath); List result = documentContext.read(deletePath); assertThat(result.size()).isEqualTo(0); @@ -265,7 +269,7 @@ public class WriteTest extends BaseTest { public void rootCannotBeConverted(){ ValueConverter valueConverter = new ValueConverter() { @Override - public Object convert(Object currentValue) { + public Object convert(Object currentValue, Configuration configuration) { return currentValue.toString()+"converted"; } }; @@ -281,13 +285,14 @@ public class WriteTest extends BaseTest { @Test public void object_can_be_converted(){ + TypeRef> typeRef = new TypeRef>() {}; ValueConverter valueConverter = new ToStringValueConverterImpl(); - DocumentContext documentContext = parse(JSON_DOCUMENT); + DocumentContext documentContext = JsonPath.using(JACKSON_CONFIGURATION).parse(JSON_DOCUMENT); Object list = documentContext.read("$..book"); assertThat(list).isInstanceOf(List.class); - String result = ((List)documentContext.convert("$..book", valueConverter).read("$..book")).get(0); + String result = documentContext.convert("$..book", valueConverter).read("$..book", typeRef).get(0); assertThat(result).isInstanceOf(String.class); - assertThat(((String)result).endsWith("converted")).isTrue(); + assertThat(result).endsWith("converted"); } @Test @@ -308,7 +313,7 @@ public class WriteTest extends BaseTest { private class ToStringValueConverterImpl implements ValueConverter{ @Override - public Object convert(Object currentValue) { + public Object convert(Object currentValue, Configuration configuration) { return currentValue.toString()+"converted"; } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/functions/NumericFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/functions/NumericFunctionTest.java index 5baad6c6..02202c38 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/functions/NumericFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/functions/NumericFunctionTest.java @@ -2,23 +2,12 @@ package com.jayway.jsonpath.functions; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configurations; -import com.jayway.jsonpath.JsonPath; -import net.minidev.json.JSONArray; -import org.junit.Ignore; import org.junit.Test; -import org.junit.experimental.theories.DataPoints; -import org.junit.experimental.theories.Theories; -import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; - -import static com.jayway.jsonpath.Configurations.*; -import static com.jayway.jsonpath.JsonPath.using; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.runners.Parameterized.Parameters; /** diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java index 7cac7629..33586dcc 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java @@ -1,17 +1,14 @@ package com.jayway.jsonpath.internal; -import static org.junit.Assert.*; - -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.Test; - import com.jayway.jsonpath.BaseTest; import com.jayway.jsonpath.Criteria; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.Filter; import com.jayway.jsonpath.JsonPath; +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import java.util.List; public class JsonReaderTest extends BaseTest { diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/token/PathTokenTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/token/PathTokenTest.java index e1e68dc4..7c572572 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/token/PathTokenTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/token/PathTokenTest.java @@ -1,17 +1,12 @@ package com.jayway.jsonpath.internal.token; import com.jayway.jsonpath.BaseTest; -import com.jayway.jsonpath.internal.token.PathToken; -import com.jayway.jsonpath.internal.token.PropertyPathToken; -import com.jayway.jsonpath.internal.token.ScanPathToken; -import com.jayway.jsonpath.internal.token.WildcardPathToken; - -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Test; import java.util.Arrays; +import static org.assertj.core.api.Assertions.assertThat; + public class PathTokenTest extends BaseTest { @Test