1818import graphql .schema .GraphQLType ;
1919import org .testng .annotations .Test ;
2020
21+ import java .lang .reflect .Field ;
22+ import java .lang .reflect .Method ;
2123import java .util .*;
2224import java .util .stream .Collectors ;
2325import java .util .stream .Stream ;
2426
2527import static graphql .Scalars .*;
28+ import static graphql .Scalars .GraphQLID ;
2629import static org .testng .Assert .*;
2730
2831public class DefaultTypeFunctionTest {
@@ -31,6 +34,21 @@ private enum A {
3134 @ GraphQLName ("someA" ) @ GraphQLDescription ("a" ) A , B
3235 }
3336
37+ public @ GraphQLID String idStringMethod () {
38+ return "asd" ;
39+ }
40+
41+ public @ GraphQLID Integer idIntegerMethod () {
42+ return 5 ;
43+ }
44+
45+ public @ GraphQLID int idIntMethod () {
46+ return 5 ;
47+ }
48+
49+ public @ GraphQLID String idStringField ;
50+ public @ GraphQLID Integer idIntegerField ;
51+ public @ GraphQLID int idIntField ;
3452
3553 @ Test
3654 public void enumeration () {
@@ -39,29 +57,89 @@ public void enumeration() {
3957 assertTrue (enumeration instanceof GraphQLEnumType );
4058 List <GraphQLEnumValueDefinition > values = ((GraphQLEnumType ) enumeration ).getValues ();
4159 assertEquals (values .stream ().
42- map (GraphQLEnumValueDefinition ::getName ).collect (Collectors .toList ()),
43- Arrays .asList ("someA" , "B" ));
60+ map (GraphQLEnumValueDefinition ::getName ).collect (Collectors .toList ()),
61+ Arrays .asList ("someA" , "B" ));
4462 assertEquals (values .stream ().
4563 map (GraphQLEnumValueDefinition ::getDescription ).collect (Collectors .toList ()),
4664 Arrays .asList ("a" , "B" ));
4765
4866 }
4967
5068 @ Test
51- public void string () {
69+ public void buildType_stringMethodAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchMethodException , NoSuchFieldException {
70+ // Arrange
71+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
72+ Method idStringMethod = DefaultTypeFunctionTest .class .getMethod ("idStringMethod" );
73+
74+ // Act+Assert
75+ assertEquals (instance .buildType (idStringMethod .getReturnType (), idStringMethod .getAnnotatedReturnType ()), GraphQLID );
76+ }
77+
78+ @ Test
79+ public void buildType_integerMethodAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchMethodException {
80+ // Arrange
81+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
82+ Method idIntegerMethod = DefaultTypeFunctionTest .class .getMethod ("idIntegerMethod" );
83+
84+ // Act+Assert
85+ assertEquals (instance .buildType (idIntegerMethod .getReturnType (), idIntegerMethod .getAnnotatedReturnType ()), GraphQLID );
86+ }
87+
88+ @ Test
89+ public void buildType_intMethodAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchMethodException {
90+ // Arrange
91+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
92+ Method idIntMethod = DefaultTypeFunctionTest .class .getMethod ("idIntMethod" );
93+
94+ // Act+Assert
95+ assertEquals (instance .buildType (idIntMethod .getReturnType (), idIntMethod .getAnnotatedReturnType ()), GraphQLID );
96+ }
97+
98+ @ Test
99+ public void buildType_stringFieldAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchFieldException {
100+ // Arrange
101+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
102+ Field idStringField = DefaultTypeFunctionTest .class .getField ("idStringField" );
103+
104+ // Act+Assert
105+ assertEquals (instance .buildType (idStringField .getType (), idStringField .getAnnotatedType ()), GraphQLID );
106+ }
107+
108+ @ Test
109+ public void buildType_integerFieldAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchFieldException {
110+ // Arrange
111+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
112+ Field idIntegerField = DefaultTypeFunctionTest .class .getField ("idIntegerField" );
113+
114+ // Act+Assert
115+ assertEquals (instance .buildType (idIntegerField .getType (), idIntegerField .getAnnotatedType ()), GraphQLID );
116+ }
117+
118+ @ Test
119+ public void buildType_intFieldAnnotatedWithGraphQLID_returnsGraphQLID () throws NoSuchFieldException {
120+ // Arrange
121+ DefaultTypeFunction instance = testedDefaultTypeFunction ();
122+ Field idIntField = DefaultTypeFunctionTest .class .getField ("idIntField" );
123+
124+ // Act+Assert
125+ assertEquals (instance .buildType (idIntField .getType (), idIntField .getAnnotatedType ()), GraphQLID );
126+ }
127+
128+ @ Test
129+ public void buildType_stringType_returnsGraphQLString () {
52130 DefaultTypeFunction instance = testedDefaultTypeFunction ();
53131 assertEquals (instance .buildType (String .class , null ), GraphQLString );
54132 }
55133
56134 @ Test
57- public void bool () {
135+ public void buildType_booleanType_returnsGraphQLBoolean () {
58136 DefaultTypeFunction instance = testedDefaultTypeFunction ();
59137 assertEquals (instance .buildType (boolean .class , null ), GraphQLBoolean );
60138 assertEquals (instance .buildType (Boolean .class , null ), GraphQLBoolean );
61139 }
62140
63141 @ Test
64- public void float_ () {
142+ public void buildType_floatType_returnsGraphQLFloat () {
65143 DefaultTypeFunction instance = testedDefaultTypeFunction ();
66144 assertEquals (instance .buildType (float .class , null ), GraphQLFloat );
67145 assertEquals (instance .buildType (Float .class , null ), GraphQLFloat );
@@ -70,35 +148,45 @@ public void float_() {
70148 }
71149
72150 @ Test
73- public void integer () {
151+ public void buildType_integerType_returnsGraphQLInt () {
74152 DefaultTypeFunction instance = testedDefaultTypeFunction ();
75153 assertEquals (instance .buildType (int .class , null ), GraphQLInt );
76154 assertEquals (instance .buildType (Integer .class , null ), GraphQLInt );
77155 }
78156
79157 @ Test
80- public void long_ () {
158+ public void buildType_longType_returnsGraphQLLong () {
81159 DefaultTypeFunction instance = testedDefaultTypeFunction ();
82160 assertEquals (instance .buildType (long .class , null ), GraphQLLong );
83161 assertEquals (instance .buildType (Long .class , null ), GraphQLLong );
84162 }
85163
86164
87165 @ SuppressWarnings ("unused" )
88- public List <List <@ GraphQLNonNull String >> listMethod () { return null ;}
166+ public List <List <@ GraphQLNonNull String >> listMethod () {
167+ return null ;
168+ }
89169
90170 @ SuppressWarnings ("unused" )
91- public Iterable <Iterable <@ GraphQLNonNull String >> iterableMethod () { return null ;}
171+ public Iterable <Iterable <@ GraphQLNonNull String >> iterableMethod () {
172+ return null ;
173+ }
92174
93175 @ SuppressWarnings ("unused" )
94- public Collection <Collection <@ GraphQLNonNull String >> collectionMethod () { return null ;}
176+ public Collection <Collection <@ GraphQLNonNull String >> collectionMethod () {
177+ return null ;
178+ }
95179
96180
97181 @ SuppressWarnings ("unused" )
98- public Stream <List <@ GraphQLNonNull String >> streamMethod () { return null ;}
182+ public Stream <List <@ GraphQLNonNull String >> streamMethod () {
183+ return null ;
184+ }
99185
100186 @ SuppressWarnings ("unused" )
101- public Set <Set <@ GraphQLNonNull String >> setMethod () { return null ;}
187+ public Set <Set <@ GraphQLNonNull String >> setMethod () {
188+ return null ;
189+ }
102190
103191 // GraphqlList(GraphqlList(GraphQlString) is expected here
104192 private void assertIsGraphListOfListOfString (GraphQLType type ) {
@@ -110,36 +198,36 @@ private void assertIsGraphListOfListOfString(GraphQLType type) {
110198 }
111199
112200 @ Test
113- public void list () throws NoSuchMethodException {
201+ public void buildType_listType_returnsCorrectGraphQLType () throws NoSuchMethodException {
114202 DefaultTypeFunction instance = testedDefaultTypeFunction ();
115203 graphql .schema .GraphQLType type = instance .buildType (getClass ().getMethod ("listMethod" ).getReturnType (), getClass ().getMethod ("listMethod" ).getAnnotatedReturnType ());
116204 assertIsGraphListOfListOfString (type );
117205 }
118206
119207
120208 @ Test
121- public void iterable () throws NoSuchMethodException {
209+ public void buildType_iterableType_returnsCorrectGraphQLType () throws NoSuchMethodException {
122210 DefaultTypeFunction instance = testedDefaultTypeFunction ();
123211 graphql .schema .GraphQLType type = instance .buildType (getClass ().getMethod ("iterableMethod" ).getReturnType (), getClass ().getMethod ("iterableMethod" ).getAnnotatedReturnType ());
124212 assertIsGraphListOfListOfString (type );
125213 }
126214
127215 @ Test
128- public void collection () throws NoSuchMethodException {
216+ public void buildType_collectionType_returnsCorrectGraphQLType () throws NoSuchMethodException {
129217 DefaultTypeFunction instance = testedDefaultTypeFunction ();
130218 graphql .schema .GraphQLType type = instance .buildType (getClass ().getMethod ("collectionMethod" ).getReturnType (), getClass ().getMethod ("collectionMethod" ).getAnnotatedReturnType ());
131219 assertIsGraphListOfListOfString (type );
132220 }
133221
134222 @ Test
135- public void set () throws NoSuchMethodException {
223+ public void buildType_setType_returnsCorrectGraphQLType () throws NoSuchMethodException {
136224 DefaultTypeFunction instance = testedDefaultTypeFunction ();
137225 graphql .schema .GraphQLType type = instance .buildType (getClass ().getMethod ("setMethod" ).getReturnType (), getClass ().getMethod ("setMethod" ).getAnnotatedReturnType ());
138226 assertIsGraphListOfListOfString (type );
139227 }
140228
141229 @ Test
142- public void stream () throws NoSuchMethodException {
230+ public void buildType_streamType_returnsCorrectGraphQLType () throws NoSuchMethodException {
143231 DefaultTypeFunction instance = testedDefaultTypeFunction ();
144232 graphql .schema .GraphQLType type = instance .buildType (getClass ().getMethod ("streamMethod" ).getReturnType (), getClass ().getMethod ("listMethod" ).getAnnotatedReturnType ());
145233 assertIsGraphListOfListOfString (type );
@@ -153,7 +241,9 @@ public void unparameterizedList() {
153241 }
154242
155243 @ SuppressWarnings ("unused" )
156- public Optional <List <@ GraphQLNonNull String >> optionalMethod () { return Optional .empty ();}
244+ public Optional <List <@ GraphQLNonNull String >> optionalMethod () {
245+ return Optional .empty ();
246+ }
157247
158248 @ Test
159249 public void optional () throws NoSuchMethodException {
@@ -193,8 +283,8 @@ public void recursiveTypes() throws Exception {
193283 GraphQLType type = instance .buildType (Class1 .class , Class2 .class .getField ("class1" ).getAnnotatedType ());
194284 GraphQLFieldDefinition class1class2 = ((GraphQLObjectType ) type ).getFieldDefinition ("class2" );
195285 assertNotNull (class1class2 );
196- assertTrue (((GraphQLObjectType )class1class2 .getType ()).getFieldDefinition ("class1" ).getType () instanceof GraphQLTypeReference );
197- assertTrue (((GraphQLObjectType )class1class2 .getType ()).getFieldDefinition ("class2" ).getType () instanceof GraphQLTypeReference );
286+ assertTrue (((GraphQLObjectType ) class1class2 .getType ()).getFieldDefinition ("class1" ).getType () instanceof GraphQLTypeReference );
287+ assertTrue (((GraphQLObjectType ) class1class2 .getType ()).getFieldDefinition ("class2" ).getType () instanceof GraphQLTypeReference );
198288 GraphQLAnnotations .instance = new GraphQLAnnotations ();
199289 }
200290
0 commit comments