-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed VariableAccumulator so it can represent itself with null valu…
…es (#2816) * Changed VariableAccumulator so it can repreent itself with null values - Collector.toMap will not allow null values * Better test
- Loading branch information
Showing
2 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/groovy/graphql/normalized/VariableAccumulatorTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package graphql.normalized | ||
|
||
import graphql.language.IntValue | ||
import graphql.language.NullValue | ||
import graphql.language.StringValue | ||
import graphql.language.TypeName | ||
import spock.lang.Specification | ||
|
||
class VariableAccumulatorTest extends Specification { | ||
|
||
def alwaysTruePredicate = new VariablePredicate() { | ||
@Override | ||
boolean shouldMakeVariable(ExecutableNormalizedField executableNormalizedField, String argName, NormalizedInputValue normalizedInputValue) { | ||
return true | ||
} | ||
} | ||
|
||
def "can build itself handing null values"() { | ||
when: | ||
VariableAccumulator accumulator = new VariableAccumulator(alwaysTruePredicate) | ||
accumulateData(accumulator) | ||
|
||
def variablesMap = accumulator.getVariablesMap() | ||
then: | ||
variablesMap == [v0: "hello", v1: 666, v2: null, v3: null] | ||
} | ||
|
||
def "can build variable definitions"() { | ||
when: | ||
VariableAccumulator accumulator = new VariableAccumulator(alwaysTruePredicate) | ||
accumulateData(accumulator) | ||
def names = accumulator.getVariableDefinitions().collect { vd -> vd.name } | ||
def typeNames = accumulator.getVariableDefinitions().collect { vd -> (vd.type as TypeName).name } | ||
|
||
then: | ||
names == ["v0", "v1", "v2", "v3"] | ||
typeNames == ["String", "Int", "Int", "String"] | ||
} | ||
|
||
private void accumulateData(VariableAccumulator accumulator) { | ||
accumulator.accumulateVariable(new NormalizedInputValue("String", StringValue.of("hello"))) | ||
accumulator.accumulateVariable(new NormalizedInputValue("Int", IntValue.of(666))) | ||
accumulator.accumulateVariable(new NormalizedInputValue("Int", NullValue.of())) | ||
accumulator.accumulateVariable(new NormalizedInputValue("String", null)) | ||
} | ||
} |