Skip to content

Commit e815baf

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

1 file changed

Lines changed: 70 additions & 74 deletions

File tree

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

Lines changed: 70 additions & 74 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.LocalTime
2628
import java.util.concurrent.TimeUnit
@@ -33,91 +35,85 @@ import java.util.*
3335
*/
3436
class GraphQLLocalTimeTest : FreeSpec({
3537

36-
/*
37-
def setup() {
38-
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
38+
"parseLiteral -> success" - {
39+
listOf(
40+
StringValue("00:00:00") to LocalTime.MIDNIGHT,
41+
StringValue("10:15:30") to LocalTime.of(10, 15, 30),
42+
StringValue("17:59:59") to LocalTime.of(17, 59, 59),
43+
).forEach { (literal, result) ->
44+
"parse literal ${literal.value} as $result" {
45+
GraphqlLocalTimeCoercing().parseLiteral(literal) shouldBe result
46+
}
47+
}
3948
}
4049

41-
@Unroll
42-
def "LocalTime parse literal #literal.value as #result"() {
43-
expect:
44-
new GraphqlLocalTimeCoercing().parseLiteral(literal) == result
45-
46-
where:
47-
literal | result
48-
new StringValue("00:00:00") | LocalTime.MIDNIGHT
49-
new StringValue("10:15:30") | LocalTime.of(10, 15, 30)
50-
new StringValue("17:59:59") | LocalTime.of(17, 59, 59)
51-
}
52-
53-
@Unroll
54-
def "LocalTime parseLiteral throws exception for invalid #literal"() {
55-
when:
56-
new GraphqlLocalTimeCoercing().parseLiteral(literal)
57-
58-
then:
59-
thrown(CoercingParseLiteralException)
60-
61-
where:
62-
literal | _
63-
new StringValue("") | _
64-
new StringValue("not a localtime") | _
50+
"parseLiteral -> fail" - {
51+
listOf(
52+
StringValue(""),
53+
StringValue("not a localtime"),
54+
Object()
55+
).forEach { literal ->
56+
"throws exception for invalid $literal" {
57+
shouldThrow<CoercingParseLiteralException> {
58+
GraphqlLocalTimeCoercing().parseLiteral(literal)
59+
}
60+
}
61+
}
6562
}
6663

67-
@Unroll
68-
def "LocalTime serialize #value into #result (#result.class)"() {
69-
expect:
70-
new GraphqlLocalTimeCoercing().serialize(value) == result
71-
72-
where:
73-
value | result
74-
LocalTime.MIDNIGHT | "00:00:00"
75-
LocalTime.of(10, 15, 30) | "10:15:30"
76-
LocalTime.of(17, 59, 59) | "17:59:59"
77-
LocalTime.of(17, 59, 59, TimeUnit.MILLISECONDS.toNanos(277)) | "17:59:59.277"
64+
"serialize -> success" - {
65+
listOf(
66+
LocalTime.MIDNIGHT to "00:00:00",
67+
LocalTime.of(10, 15, 30) to "10:15:30",
68+
LocalTime.of(17, 59, 59) to "17:59:59",
69+
LocalTime.of(17, 59, 59, TimeUnit.MILLISECONDS.toNanos(277).toInt()) to "17:59:59.277",
70+
).forEach { (value, result) ->
71+
"serialize $value into $result (${result::class.java})" {
72+
GraphqlLocalTimeCoercing().serialize(value) shouldBe result
73+
}
74+
}
7875
}
7976

80-
@Unroll
81-
def "serialize throws exception for invalid input #value"() {
82-
when:
83-
new GraphqlLocalTimeCoercing().serialize(value)
84-
then:
85-
thrown(CoercingSerializeException)
86-
87-
where:
88-
value | _
89-
"" | _
90-
"not a localtime" | _
91-
new Object() | _
77+
"serialize -> fail" - {
78+
listOf(
79+
"",
80+
"not a localtime",
81+
Object()
82+
).forEach { value ->
83+
"throws exception for invalid input $value" {
84+
shouldThrow<CoercingSerializeException> {
85+
GraphqlLocalTimeCoercing().serialize(value)
86+
}
87+
}
88+
}
9289
}
9390

94-
@Unroll
95-
def "LocalTime parse #value into #result (#result.class)"() {
96-
expect:
97-
new GraphqlLocalTimeCoercing().parseValue(value) == result
98-
99-
where:
100-
value | result
101-
"00:00:00" | LocalTime.MIDNIGHT
102-
"10:15:30" | LocalTime.of(10, 15, 30)
103-
"17:59:59" | LocalTime.of(17, 59, 59)
104-
"17:59:59.277" | LocalTime.of(17, 59, 59, TimeUnit.MILLISECONDS.toNanos(277))
91+
"parseValue -> success" - {
92+
listOf(
93+
"00:00:00" to LocalTime.MIDNIGHT,
94+
"10:15:30" to LocalTime.of(10, 15, 30),
95+
"17:59:59" to LocalTime.of(17, 59, 59),
96+
"17:59:59.277" to LocalTime.of(17, 59, 59, TimeUnit.MILLISECONDS.toNanos(277).toInt())
97+
).forEach { (value, result) ->
98+
"parse $value into $result (${result::class.java})" {
99+
GraphqlLocalTimeCoercing().parseValue(value) shouldBe result
100+
}
101+
}
105102
}
106103

107-
@Unroll
108-
def "parseValue throws exception for invalid input #value"() {
109-
when:
110-
new GraphqlLocalTimeCoercing().parseValue(value)
111-
then:
112-
thrown(CoercingParseValueException)
113-
114-
where:
115-
value | _
116-
"" | _
117-
"not a localtime" | _
118-
new Object() | _
104+
"parseValue -> fail" - {
105+
listOf(
106+
"",
107+
"not a localtime",
108+
Object()
109+
).forEach { value ->
110+
"throws exception for invalid input $value" {
111+
shouldThrow<CoercingParseValueException> {
112+
GraphqlLocalTimeCoercing().parseValue(value)
113+
}
114+
}
115+
}
119116
}
120-
*/
121117

122118
}) {
123119
init {

0 commit comments

Comments
 (0)