|
| 1 | +package graphql.annotations.directives.creation; |
| 2 | + |
| 3 | +import graphql.annotations.annotationTypes.GraphQLDescription; |
| 4 | +import graphql.annotations.processor.ProcessingElementsContainer; |
| 5 | +import graphql.annotations.processor.directives.CommonPropertiesCreator; |
| 6 | +import graphql.annotations.processor.directives.DirectiveArgumentCreator; |
| 7 | +import graphql.annotations.processor.typeFunctions.TypeFunction; |
| 8 | +import graphql.schema.GraphQLArgument; |
| 9 | +import org.mockito.Mockito; |
| 10 | +import org.testng.annotations.BeforeMethod; |
| 11 | +import org.testng.annotations.Test; |
| 12 | + |
| 13 | +import java.lang.reflect.Field; |
| 14 | + |
| 15 | +import static graphql.Scalars.GraphQLBoolean; |
| 16 | +import static org.mockito.ArgumentMatchers.any; |
| 17 | +import static org.mockito.ArgumentMatchers.same; |
| 18 | +import static org.mockito.Mockito.when; |
| 19 | +import static org.testng.AssertJUnit.assertEquals; |
| 20 | + |
| 21 | +public class DirectiveArgumentCreatorTest { |
| 22 | + @GraphQLDescription("isActive") |
| 23 | + private boolean isActive = true; |
| 24 | + private DirectiveArgumentCreator directiveArgumentCreator; |
| 25 | + |
| 26 | + private TypeFunction typeFunction; |
| 27 | + private ProcessingElementsContainer container; |
| 28 | + |
| 29 | + @BeforeMethod |
| 30 | + public void setUp() throws NoSuchFieldException { |
| 31 | + CommonPropertiesCreator commonPropertiesCreator = Mockito.mock(CommonPropertiesCreator.class); |
| 32 | + typeFunction = Mockito.mock(TypeFunction.class); |
| 33 | + Field field = this.getClass().getDeclaredField("isActive"); |
| 34 | + container = Mockito.mock(ProcessingElementsContainer.class); |
| 35 | + when(typeFunction.buildType(same(true), same(boolean.class), any(), same(container))).thenReturn(GraphQLBoolean); |
| 36 | + when(commonPropertiesCreator.getName(any())).thenCallRealMethod(); |
| 37 | + when(commonPropertiesCreator.getDescription(any())).thenCallRealMethod(); |
| 38 | + directiveArgumentCreator = new DirectiveArgumentCreator(commonPropertiesCreator, typeFunction, container); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void getArgument_goodFieldSupplied_correctArgumentCreated() throws NoSuchFieldException { |
| 43 | + GraphQLArgument isActive = directiveArgumentCreator.getArgument(this.getClass().getDeclaredField("isActive"), DirectiveArgumentCreatorTest.class); |
| 44 | + // Assert |
| 45 | + assertEquals(isActive.getName(), "isActive"); |
| 46 | + assertEquals(isActive.getDefaultValue(), true); |
| 47 | + assertEquals(isActive.getDescription(), "isActive"); |
| 48 | + assertEquals(isActive.getType(), GraphQLBoolean); |
| 49 | + } |
| 50 | +} |
0 commit comments