Browse Source

fixing broken tests

changing format of functions path expr with/without args
removing errant unwrap call - added to test
pull/167/head
Matthew J Greenwood 9 years ago
parent
commit
01bdbe2cc3
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/path/FunctionPathToken.java
  2. 2
      json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
  3. 5
      json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java

2
json-path/src/main/java/com/jayway/jsonpath/internal/path/FunctionPathToken.java

@ -21,7 +21,7 @@ public class FunctionPathToken extends PathToken {
private final List<Parameter> functionParams; private final List<Parameter> functionParams;
public FunctionPathToken(String pathFragment, List<Parameter> parameters) { public FunctionPathToken(String pathFragment, List<Parameter> parameters) {
this.pathFragment = pathFragment; this.pathFragment = pathFragment + ((parameters != null && parameters.size() > 0) ? "(...)" : "()");
if(null != pathFragment){ if(null != pathFragment){
functionName = pathFragment; functionName = pathFragment;
functionParams = parameters; functionParams = parameters;

2
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java

@ -52,7 +52,7 @@ public abstract class AbstractJsonProvider implements JsonProvider {
public Object getLastElement(Object obj) { public Object getLastElement(Object obj) {
if (null != obj) { if (null != obj) {
int len = this.length(obj); int len = this.length(obj);
return unwrap(getArrayIndex(obj, len-1)); return getArrayIndex(obj, len-1);
} }
return null; return null;
} }

5
json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java

@ -15,9 +15,6 @@ public class BaseFunctionTest {
protected static final String NUMBER_SERIES = "{\"empty\": [], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}"; protected static final String NUMBER_SERIES = "{\"empty\": [], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}";
protected static final String TEXT_SERIES = "{\"urls\": [\"http://api.worldbank.org/countries/all/?format=json\", \"http://api.worldbank.org/countries/all/?format=json\"], \"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ]}"; protected static final String TEXT_SERIES = "{\"urls\": [\"http://api.worldbank.org/countries/all/?format=json\", \"http://api.worldbank.org/countries/all/?format=json\"], \"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ]}";
/** /**
* Verify the function returns the correct result based on the input expectedValue * Verify the function returns the correct result based on the input expectedValue
* *
@ -32,7 +29,7 @@ public class BaseFunctionTest {
*/ */
protected void verifyFunction(Configuration conf, String pathExpr, String json, Object expectedValue) { protected void verifyFunction(Configuration conf, String pathExpr, String json, Object expectedValue) {
Object result = using(conf).parse(json).read(pathExpr); Object result = using(conf).parse(json).read(pathExpr);
assertThat(result).isEqualTo(expectedValue); assertThat(conf.jsonProvider().unwrap(result)).isEqualTo(expectedValue);
} }
protected void verifyMathFunction(Configuration conf, String pathExpr, Object expectedValue) { protected void verifyMathFunction(Configuration conf, String pathExpr, Object expectedValue) {

Loading…
Cancel
Save