@Test(expectedExceptions = InvalidDirectiveLocationException.class) public void wireGraphQLScalarType_invalidLocations_exceptionIsThrown() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLScalarType directiveContainer = GraphQLString; AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); }
@Test public void wireGraphQLScalarType_validLocations_correctMethodIsCalled() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLScalarType directiveContainer = GraphQLString; AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.SCALAR).build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); // Assert verify(upperWiring).onScalar(upperCaseEnv); }