|
24 | 24 | import java.time.LocalTime; |
25 | 25 | import java.time.Month; |
26 | 26 | import java.time.ZoneId; |
| 27 | +import java.util.Map; |
27 | 28 | import java.util.concurrent.TimeUnit; |
28 | 29 |
|
| 30 | +import com.introproventures.graphql.jpa.query.converter.model.VariableValue; |
| 31 | +import com.introproventures.graphql.jpa.query.schema.JavaScalars.GraphQLObjectCoercing; |
29 | 32 | import graphql.language.StringValue; |
30 | 33 | import graphql.schema.Coercing; |
31 | 34 | import graphql.schema.CoercingParseValueException; |
32 | 35 | import graphql.schema.CoercingSerializeException; |
| 36 | +import graphql.schema.GraphQLScalarType; |
33 | 37 | import org.junit.Test; |
34 | 38 |
|
35 | 39 | public class JavaScalarsTest { |
@@ -173,12 +177,38 @@ public void testLocalTimeParseValueInvlidValue() { |
173 | 177 | //given |
174 | 178 | Coercing<?,?> coercing = JavaScalars.of(LocalTime.class).getCoercing(); |
175 | 179 |
|
176 | | - //then |
177 | 180 | //then |
178 | 181 | coercing.parseValue(""); |
179 | 182 | coercing.parseValue("not a time"); |
180 | 183 | coercing.parseValue(new Object()); |
181 | 184 |
|
182 | 185 | fail("Should throw CoercingParseValueException"); |
183 | 186 | } |
| 187 | + |
| 188 | + @Test |
| 189 | + public void testNonExistingJavaScalarShouldDefaultToObjectCoercing() { |
| 190 | + //given |
| 191 | + GraphQLScalarType scalarType = JavaScalars.of(VariableValue.class); |
| 192 | + |
| 193 | + //then |
| 194 | + Coercing<?,?> coercing = scalarType.getCoercing(); |
| 195 | + |
| 196 | + assertThat(coercing).isInstanceOf(GraphQLObjectCoercing.class); |
| 197 | + assertThat(scalarType.getName()).isEqualTo("VariableValue"); |
| 198 | + } |
| 199 | + |
| 200 | + @Test |
| 201 | + public void testRegisterJavaScalarWithObjectCoercing() { |
| 202 | + //given |
| 203 | + JavaScalars.register(Map.class, new GraphQLScalarType("Map", "Map Object Type", new GraphQLObjectCoercing())); |
| 204 | + |
| 205 | + //when |
| 206 | + GraphQLScalarType scalarType = JavaScalars.of(Map.class); |
| 207 | + |
| 208 | + //then |
| 209 | + Coercing<?,?> coercing = scalarType.getCoercing(); |
| 210 | + |
| 211 | + assertThat(coercing).isInstanceOf(GraphQLObjectCoercing.class); |
| 212 | + assertThat(scalarType.getName()).isEqualTo("Map"); |
| 213 | + } |
184 | 214 | } |
0 commit comments