Browse Source

fix for PathToken.isUpstreamDefinite

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
630f0c15b3
  1. 6
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  2. 53
      json-path/src/test/java/com/jayway/jsonpath/PathTokenTest.java

6
json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

@ -30,7 +30,7 @@ public abstract class PathToken {
private Boolean definite = null;
private Boolean upstreamDefinite = null;
PathToken appendTailToken(PathToken next) {
public PathToken appendTailToken(PathToken next) {
this.next = next;
this.next.prev = this;
return next;
@ -148,13 +148,13 @@ public abstract class PathToken {
return prev == null;
}
boolean isUpstreamDefinite(){
public boolean isUpstreamDefinite(){
if(upstreamDefinite != null){
return upstreamDefinite.booleanValue();
}
boolean isUpstreamDefinite = isTokenDefinite();
if (isUpstreamDefinite && !isRoot()) {
isUpstreamDefinite = prev.isPathDefinite();
isUpstreamDefinite = prev.isUpstreamDefinite();
}
upstreamDefinite = isUpstreamDefinite;
return isUpstreamDefinite;

53
json-path/src/test/java/com/jayway/jsonpath/PathTokenTest.java

@ -0,0 +1,53 @@
package com.jayway.jsonpath;
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;
public class PathTokenTest extends BaseTest {
@Test
public void is_upstream_definite_in_simple_case() {
assertThat(makePathReturningTail(makePPT("foo")).isUpstreamDefinite()).isTrue();
assertThat(makePathReturningTail(makePPT("foo"), makePPT("bar")).isUpstreamDefinite()).isTrue();
assertThat(makePathReturningTail(makePPT("foo", "foo2"), makePPT("bar")).isUpstreamDefinite()).isFalse();
assertThat(makePathReturningTail(new WildcardPathToken(), makePPT("bar")).isUpstreamDefinite()).isFalse();
assertThat(makePathReturningTail(new ScanPathToken(), makePPT("bar")).isUpstreamDefinite()).isFalse();
}
@Test
public void is_upstream_definite_in_complex_case() {
assertThat(makePathReturningTail(makePPT("foo"), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isTrue();
assertThat(makePathReturningTail(makePPT("foo"), new WildcardPathToken()).isUpstreamDefinite()).isFalse();
assertThat(makePathReturningTail(new WildcardPathToken(), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isFalse();
}
private PathToken makePPT(final String ... properties) {
return new PropertyPathToken(Arrays.asList(properties));
}
private PathToken makePathReturningTail(final PathToken ... tokens) {
PathToken last = null;
for (final PathToken token : tokens) {
if (last != null) {
last.appendTailToken(token);
}
last = token;
}
return last;
}
}
Loading…
Cancel
Save