@Test(expectedExceptions = InvalidDirectiveLocationException.class) public void wireFieldDefinition_invalidLocations_exceptionIsThrown() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") .type(GraphQLString).build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); }
@Test public void wireFieldDefinition_validLocations_correctMethodIsCalled() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); AnnotationsDirectiveWiring lowerWiring = mock(AnnotationsDirectiveWiring.class); GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") .type(GraphQLString).build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); AnnotationsWiringEnvironmentImpl lowerCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("lowerCase")); when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); when(lowerWiring.onField(lowerCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocations(Introspection.DirectiveLocation.FIELD).build(); map.put(upperCase, upperWiring); map.put(lowerCase, lowerWiring); // Act directiveWirer.wire(directiveContainer, map); // Assert verify(upperWiring).onField(upperCaseEnv); verify(lowerWiring).onField(lowerCaseEnv); }