Skip to content

Commit a017f72

Browse files
committed
Migrated some tests to kotest.
1 parent 3d36b3a commit a017f72

1 file changed

Lines changed: 90 additions & 102 deletions

File tree

graphql-java-datetime/src/test/kotlin/com/tailrocks/graphql/datetime/GraphQLLocalDateTest.kt

Lines changed: 90 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22+
import io.kotest.assertions.throwables.shouldThrow
2223
import io.kotest.core.spec.style.FreeSpec
2324
import io.kotest.core.spec.style.FunSpec
25+
import io.kotest.matchers.shouldBe
2426

2527
import java.time.LocalDate
2628
import java.time.ZoneOffset
@@ -35,123 +37,109 @@ import java.util.*
3537
*/
3638
class GraphQLLocalDateTest : FreeSpec({
3739

38-
/*
39-
def setup() {
40-
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
41-
}
42-
43-
@Unroll
44-
def "LocalDate parse literal #literal.value as #result"() {
45-
expect:
46-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseLiteral(literal) == result
47-
48-
where:
49-
literal | result
50-
new StringValue("2017-07-09") | LocalDate.of(2017, 7, 9)
51-
}
52-
53-
@Unroll
54-
def "LocalDate parseLiteral throws exception for invalid #literal"() {
55-
when:
56-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseLiteral(literal)
57-
58-
then:
59-
thrown(CoercingParseLiteralException)
60-
61-
where:
62-
literal | _
63-
new StringValue("") | _
64-
new StringValue("not a localdate") | _
40+
"parseLiteral -> success" - {
41+
listOf(
42+
StringValue("2017-07-09") to LocalDate.of(2017, 7, 9)
43+
).forEach { (literal, result) ->
44+
"parse literal ${literal.value} as $result" {
45+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseLiteral(literal) shouldBe result
46+
}
47+
}
6548
}
6649

67-
@Unroll
68-
def "LocalDate serialize #value into #result (#result.class)"() {
69-
expect:
70-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).serialize(value) == result
71-
72-
where:
73-
value | result
74-
LocalDate.of(2017, 7, 9) | "2017-07-09"
50+
"parseLiteral -> fail" - {
51+
listOf(
52+
StringValue(""),
53+
StringValue("not a localdate"),
54+
Object()
55+
).forEach { literal ->
56+
shouldThrow<CoercingParseLiteralException> {
57+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseLiteral(literal)
58+
}
59+
}
7560
}
7661

77-
@Unroll
78-
def "serialize throws exception for invalid input #value"() {
79-
when:
80-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).serialize(value)
81-
then:
82-
thrown(CoercingSerializeException)
83-
84-
where:
85-
value | _
86-
"" | _
87-
"not a localdate" | _
88-
new Object() | _
62+
"serialize -> success" - {
63+
listOf(
64+
LocalDate.of(2017, 7, 9) to "2017-07-09"
65+
).forEach { (value, result) ->
66+
"serialize $value into $result (${result::class.java})" {
67+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).serialize(value) shouldBe result
68+
}
69+
}
8970
}
9071

91-
@Unroll
92-
def "LocalDate parse #value into #result (#result.class)"() {
93-
expect:
94-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseValue(value) == result
95-
96-
where:
97-
value | result
98-
"2017-07-09" | LocalDate.of(2017, 7, 9)
72+
"serialize -> fail" - {
73+
listOf(
74+
"",
75+
"not a localdate",
76+
Object()
77+
).forEach { value ->
78+
"throws exception for invalid input $value" {
79+
shouldThrow<CoercingSerializeException> {
80+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).serialize(value)
81+
}
82+
83+
}
84+
}
9985
}
10086

101-
@Unroll
102-
def "LocalDate parse #value into #result (#result.class) using zone conversion"() {
103-
when:
104-
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.ofHours(2)))
105-
106-
then:
107-
new GraphqlLocalDateCoercing(true, ISO_LOCAL_DATE).parseValue(value) == result
108-
109-
where:
110-
value | result
111-
"2019-03-01" | LocalDate.of(2019, 3, 1)
112-
"2019-03-01T22:00:00Z" | LocalDate.of(2019, 3, 2)
87+
"parseValue -> success" - {
88+
listOf(
89+
"2017-07-09" to LocalDate.of(2017, 7, 9)
90+
).forEach { (value, result) ->
91+
"parse $value into $result (${result::class.java})" {
92+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseValue(value) shouldBe result
93+
}
94+
}
11395
}
11496

115-
@Unroll
116-
def "parseValue throws exception for invalid input #value"() {
117-
when:
118-
new GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseValue(value)
119-
then:
120-
thrown(CoercingParseValueException)
121-
122-
where:
123-
value | _
124-
"" | _
125-
"not a date" | _
126-
new Object() | _
97+
"parseValue -> fail" - {
98+
listOf(
99+
"",
100+
"not a date",
101+
Object()
102+
).forEach { value ->
103+
shouldThrow<CoercingParseValueException> {
104+
GraphqlLocalDateCoercing(false, ISO_LOCAL_DATE).parseValue(value)
105+
}
106+
}
127107
}
128108

129-
@Unroll
130-
def "LocalDate parse #value into #result (#result.class) with custom formatter"() {
131-
given:
132-
def formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy")
133-
134-
expect:
135-
new GraphqlLocalDateCoercing(false, formatter).parseValue(value) == result
136-
137-
where:
138-
value | result
139-
"02/09/1993" | LocalDate.of(1993, 2, 9)
109+
"zone conversion" - {
110+
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.ofHours(2)))
111+
112+
"parseValue -> success" - {
113+
listOf(
114+
"2019-03-01" to LocalDate.of(2019, 3, 1),
115+
"2019-03-01T22:00:00Z" to LocalDate.of(2019, 3, 2)
116+
).forEach { (value, result) ->
117+
"parse $value into $result (${result::class.java}) using zone conversion" {
118+
GraphqlLocalDateCoercing(true, ISO_LOCAL_DATE).parseValue(value) shouldBe result
119+
}
120+
}
121+
}
140122
}
141123

142-
@Unroll
143-
def "LocalDate serialize #value into #result (#result.class) with custom formatting"() {
144-
given:
145-
def formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy")
146-
147-
expect:
148-
new GraphqlLocalDateCoercing(false, formatter).serialize(value) == result
149-
150-
where:
151-
value | result
152-
LocalDate.of(2020, 7, 6) | "07/06/2020"
124+
"custom formatter" - {
125+
val formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy")
126+
127+
"parseValue -> success" - {
128+
listOf(
129+
"02/09/1993" to LocalDate.of(1993, 2, 9)
130+
).forEach { (value, result) ->
131+
GraphqlLocalDateCoercing(false, formatter).parseValue(value) shouldBe result
132+
}
133+
}
134+
135+
"serialize -> success" - {
136+
listOf(
137+
LocalDate.of(2020, 7, 6) to "07/06/2020"
138+
).forEach { (value, result) ->
139+
GraphqlLocalDateCoercing(false, formatter).serialize(value) shouldBe result
140+
}
141+
}
153142
}
154-
*/
155143

156144
}) {
157145
init {

0 commit comments

Comments
 (0)