@@ -19,8 +19,10 @@ import graphql.language.StringValue
1919import graphql.schema.CoercingParseLiteralException
2020import graphql.schema.CoercingParseValueException
2121import graphql.schema.CoercingSerializeException
22+ import io.kotest.assertions.throwables.shouldThrow
2223import io.kotest.core.spec.style.FreeSpec
2324import io.kotest.core.spec.style.FunSpec
25+ import io.kotest.matchers.shouldBe
2426
2527import java.time.YearMonth
2628
@@ -32,89 +34,82 @@ import java.util.*
3234 */
3335class GraphQLYearMonthTest : FreeSpec ({
3436
35- /*
36- def setup() {
37- TimeZone.setDefault(TimeZone.getTimeZone(UTC))
37+ " parseLiteral -> success" - {
38+ listOf(
39+ StringValue ("2017-07-09T11:54:42.277Z") to YearMonth .of(2017, 7),
40+ StringValue ("2017-07-09T13:14:45.947Z") to YearMonth .of(2017, 7),
41+ StringValue ("2017-07-09T11:54:42Z") to YearMonth .of(2017, 7),
42+ StringValue ("2017-07-09") to YearMonth .of(2017, 7)
43+ ).forEach { (literal, result) ->
44+ " parse literal ${literal.value} as $result " {
45+ GraphqlYearMonthCoercing ().parseLiteral(literal) shouldBe result
46+ }
47+ }
3848 }
3949
40- @Unroll
41- def "YearMonth parse literal #literal.value as #result"() {
42- expect:
43- new GraphqlYearMonthCoercing().parseLiteral(literal) == result
44-
45- where:
46- literal | result
47- new StringValue("2017-07-09T11:54:42.277Z") | YearMonth.of(2017, 7)
48- new StringValue("2017-07-09T13:14:45.947Z") | YearMonth.of(2017, 7)
49- new StringValue("2017-07-09T11:54:42Z") | YearMonth.of(2017, 7)
50- new StringValue("2017-07-09") | YearMonth.of(2017, 7)
51- }
52-
53- @Unroll
54- def "YearMonth parseLiteral throws exception for invalid #literal"() {
55- when:
56- new GraphqlYearMonthCoercing().parseLiteral(literal)
57-
58- then:
59- thrown(CoercingParseLiteralException)
60-
61- where:
62- literal | _
63- new StringValue("") | _
64- new StringValue("not a date") | _
50+ " parseLiteral -> fail" - {
51+ listOf(
52+ StringValue (""),
53+ StringValue ("not a date")
54+ ).forEach { literal ->
55+ " throws exception for invalid $literal " {
56+ shouldThrow<CoercingParseLiteralException > {
57+ GraphqlYearMonthCoercing ().parseLiteral(literal)
58+ }
59+ }
60+ }
6561 }
6662
67- @Unroll
68- def "YearMonth serialize #value into #result (#result.class)"() {
69- expect:
70- new GraphqlYearMonthCoercing().serialize( value) == result
71-
72- where:
73- value | result
74- YearMonth.of(2017, 7) | "2017-07"
63+ " serialize -> success " - {
64+ listOf(
65+ YearMonth .of(2017, 7) to "2017-07"
66+ ).forEach { ( value, result) ->
67+ " serialize $value into $result ( ${result:: class .java} ) " {
68+ GraphqlYearMonthCoercing ().serialize(value) shouldBe result
69+ }
70+ }
7571 }
7672
77- @Unroll
78- def "serialize throws exception for invalid input #value"() {
79- when:
80- new GraphqlYearMonthCoercing().serialize(value)
81- then:
82- thrown(CoercingSerializeException)
83-
84- where:
85- value | _
86- "" | _
87- "not a date" | _
88- new Object() | _
73+ " serialize -> fail " - {
74+ listOf(
75+ "",
76+ "not a date",
77+ Object ()
78+ ).forEach { value ->
79+ " throws exception for invalid input $value " {
80+ shouldThrow< CoercingSerializeException > {
81+ GraphqlYearMonthCoercing ().serialize(value)
82+ }
83+ }
84+ }
8985 }
9086
91- @Unroll
92- def "YearMonth parse #value into #result (#result.class)"() {
93- expect:
94- new GraphqlYearMonthCoercing().parseValue(value) == result
95-
96- where:
97- value | result
98- "2020-07-09T11:54:42.277Z" | YearMonth.of(2020, 7)
99- "2020-07-09T13:14:45.947Z" | YearMonth.of(2020, 7)
100- "2020-1" | YearMonth.of(2020, 1)
101- "2020-11" | YearMonth.of(2020, 11)
87+ " parseValue -> success " - {
88+ listOf(
89+ "2020-07-09T11:54:42.277Z" to YearMonth .of(2020, 7),
90+ "2020-07-09T13:14:45.947Z" to YearMonth .of(2020, 7),
91+ "2020-1" to YearMonth .of(2020, 1),
92+ "2020-11" to YearMonth .of(2020, 11),
93+ ).forEach { ( value, result) ->
94+ " parse $value into $result ( ${result:: class .java} ) " {
95+ GraphqlYearMonthCoercing ().parseValue(value) shouldBe result
96+ }
97+ }
10298 }
10399
104- @Unroll
105- def "parseValue throws exception for invalid input #value"() {
106- when:
107- new GraphqlYearMonthCoercing().parseValue(value)
108- then:
109- thrown(CoercingParseValueException)
110-
111- where:
112- value | _
113- "" | _
114- "not a date" | _
115- new Object() | _
100+ " parseValue -> fail " - {
101+ listOf(
102+ "",
103+ "not a date",
104+ Object (),
105+ ).forEach { value ->
106+ " throws exception for invalid input $value " {
107+ shouldThrow< CoercingParseValueException > {
108+ GraphqlYearMonthCoercing ().parseValue(value)
109+ }
110+ }
111+ }
116112 }
117- */
118113
119114}) {
120115 init {
0 commit comments