Skip to content

Commit 42dc1be

Browse files
committed
more tests
1 parent d223c15 commit 42dc1be

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

src/main/java/graphql/language/NodeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package graphql.language;
22

3+
import graphql.Internal;
34
import graphql.util.TraversalControl;
45
import graphql.util.TraverserContext;
56

7+
@Internal
68
public interface NodeVisitor {
79
TraversalControl visitArgument(Argument node, TraverserContext<Node> data);
810

src/main/java/graphql/language/NodeVisitorStub.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package graphql.language;
22

3+
import graphql.Internal;
34
import graphql.util.TraversalControl;
45
import graphql.util.TraverserContext;
56

6-
public abstract class NodeVisitorStub
7+
@Internal
8+
public class NodeVisitorStub
79
implements NodeVisitor {
810
@Override
911
public TraversalControl visitArgument(Argument node, TraverserContext<Node> context) {

src/main/java/graphql/util/SimpleTraverserContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package graphql.util;
22

3+
import graphql.Internal;
4+
35
import java.util.LinkedHashMap;
46
import java.util.Map;
57
import java.util.Set;
68

9+
@Internal
710
public class SimpleTraverserContext<T> implements TraverserContext<T> {
811

912
private final Map<Class<?>, Object> vars = new LinkedHashMap<>();

src/main/java/graphql/util/TraverserVisitor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ public interface TraverserVisitor<T> {
77

88
TraversalControl enter(TraverserContext<T> context);
99

10+
/**
11+
* @return Only Continue or Quit allowed
12+
*/
1013
TraversalControl leave(TraverserContext<T> context);
1114

15+
/**
16+
* @return Only Continue or Quit allowed
17+
*/
1218
default TraversalControl backRef(TraverserContext<T> context) {
1319
return TraversalControl.CONTINUE;
1420
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package graphql.language
2+
3+
import graphql.util.TraversalControl
4+
import graphql.util.TraverserContext
5+
import spock.lang.Specification
6+
7+
class NodeVisitorStubTest extends Specification {
8+
9+
10+
def "selection nodes call visitSelection by default"() {
11+
given:
12+
NodeVisitorStub nodeVisitorStub = Spy(NodeVisitorStub, constructorArgs: [])
13+
Field field = new Field()
14+
FragmentSpread fragmentSpread = new FragmentSpread()
15+
InlineFragment inlineFragment = new InlineFragment()
16+
TraverserContext context = Mock(TraverserContext)
17+
18+
when:
19+
def control = nodeVisitorStub.visitField(field, context)
20+
21+
then:
22+
1 * nodeVisitorStub.visitSelection(field, context) >> TraversalControl.QUIT
23+
control == TraversalControl.QUIT
24+
25+
when:
26+
control = nodeVisitorStub.visitInlineFragment(inlineFragment, context)
27+
28+
then:
29+
1 * nodeVisitorStub.visitSelection(inlineFragment, context) >> TraversalControl.QUIT
30+
control == TraversalControl.QUIT
31+
32+
when:
33+
control = nodeVisitorStub.visitFragmentSpread(fragmentSpread, context)
34+
35+
then:
36+
1 * nodeVisitorStub.visitSelection(fragmentSpread, context) >> TraversalControl.QUIT
37+
control == TraversalControl.QUIT
38+
}
39+
40+
// TODO: more testing
41+
}

0 commit comments

Comments
 (0)