Skip to content

Commit 0be159f

Browse files
committed
#438 - unit test for NonNullableFieldValidator
1 parent 42dc83f commit 0be159f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package graphql.execution
2+
3+
import spock.lang.Specification
4+
5+
import static graphql.Scalars.GraphQLString
6+
import static graphql.schema.GraphQLNonNull.nonNull
7+
8+
class NonNullableFieldValidatorTest extends Specification {
9+
10+
ExecutionContext context = new ExecutionContext(null, null, null, null, null, null, null, null, null, null)
11+
12+
def "non nullable field throws exception"() {
13+
TypeInfo typeInfo = TypeInfo.newTypeInfo().type(nonNull(GraphQLString)).build()
14+
15+
NonNullableFieldValidator validator = new NonNullableFieldValidator(context, typeInfo)
16+
17+
when:
18+
validator.validate(null)
19+
20+
then:
21+
thrown(NonNullableFieldWasNullException)
22+
23+
}
24+
25+
def "nullable field does not throw exception"() {
26+
TypeInfo typeInfo = TypeInfo.newTypeInfo().type(GraphQLString).build()
27+
28+
NonNullableFieldValidator validator = new NonNullableFieldValidator(context, typeInfo)
29+
30+
when:
31+
def result = validator.validate(null)
32+
33+
then:
34+
result == null
35+
}
36+
}

0 commit comments

Comments
 (0)