File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed
test/groovy/graphql/language Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 11package graphql .language ;
22
3+ import graphql .Internal ;
34import graphql .util .TraversalControl ;
45import graphql .util .TraverserContext ;
56
7+ @ Internal
68public interface NodeVisitor {
79 TraversalControl visitArgument (Argument node , TraverserContext <Node > data );
810
Original file line number Diff line number Diff line change 11package graphql .language ;
22
3+ import graphql .Internal ;
34import graphql .util .TraversalControl ;
45import 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 ) {
Original file line number Diff line number Diff line change 11package graphql .util ;
22
3+ import graphql .Internal ;
4+
35import java .util .LinkedHashMap ;
46import java .util .Map ;
57import java .util .Set ;
68
9+ @ Internal
710public class SimpleTraverserContext <T > implements TraverserContext <T > {
811
912 private final Map <Class <?>, Object > vars = new LinkedHashMap <>();
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments