Skip to content

Commit a044ea7

Browse files
committed
Init tests migration.
1 parent 8bdb447 commit a044ea7

8 files changed

Lines changed: 142 additions & 115 deletions

File tree

buildSrc/src/main/kotlin/kotest-conventions.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ plugins {
33
id("com.tailrocks.kotlin")
44
}
55

6+
val catalogs = extensions.getByType<VersionCatalogsExtension>()
7+
8+
val libs = catalogs.named("libs")
9+
610
dependencies {
7-
// Kotest
8-
//testImplementation(libs.kotest.runner.junit)
9-
//testImplementation(libs.kotest.assertions.core)
11+
testImplementation(libs.findLibrary("kotest.runner.junit").orElseThrow())
12+
testImplementation(libs.findLibrary("kotest.assertions.core").orElseThrow())
13+
testImplementation(libs.findLibrary("kotest.framework.datatest").orElseThrow())
1014
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ tailrocks-kotlin-conventions = { module = "com.tailrocks.gradle:kotlin-conventio
2222
tailrocks-junit-conventions = { module = "com.tailrocks.gradle:junit-conventions", version = "0.2.0" }
2323
kotest-runner-junit = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
2424
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
25+
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }
2526

2627
[plugins]
2728
test-logger = { id = "com.adarshr.test-logger", version = "3.2.0" }

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

Lines changed: 101 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,104 +15,121 @@
1515
*/
1616
package com.tailrocks.graphql.datetime
1717

18+
import com.tailrocks.graphql.datetime.DateTimeHelper.createDate
1819
import graphql.language.StringValue
19-
import graphql.schema.CoercingParseLiteralException
20-
import graphql.schema.CoercingParseValueException
21-
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
24-
25-
import static com.tailrocks.graphql.datetime.DateTimeHelper.createDate
26-
import static java.time.ZoneOffset.UTC
20+
import io.kotest.core.spec.style.FunSpec
21+
import io.kotest.datatest.withData
22+
import io.kotest.matchers.shouldBe
23+
import java.time.ZoneOffset.UTC
24+
import java.util.*
2725

2826
/**
2927
* @author Alexey Zhokhov
3028
*/
31-
class GraphQLDateTest extends Specification {
32-
33-
def setup() {
34-
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
29+
class GraphQLDateTest : FunSpec({
30+
31+
context("parse literal") {
32+
data class Item(val literal: StringValue, val result: Date)
33+
34+
withData(
35+
nameFn = { "${it.literal} -> ${it.result}" },
36+
listOf(
37+
Item(
38+
StringValue("2017-07-09T11:54:42.277Z"),
39+
createDate(2017, 7, 9, 11, 54, 42, 277)
40+
),
41+
Item(
42+
StringValue("2017-07-09T13:14:45.947Z"),
43+
createDate(2017, 7, 9, 13, 14, 45, 947),
44+
),
45+
Item(
46+
StringValue("2017-07-09T11:54:42Z"),
47+
createDate(2017, 7, 9, 11, 54, 42),
48+
),
49+
Item(
50+
StringValue("2017-07-09"),
51+
createDate(2017, 7, 9)
52+
)
53+
)
54+
) { (literal: StringValue, result: Date) ->
55+
GraphqlDateCoercing().parseLiteral(literal) shouldBe result
56+
}
3557
}
3658

37-
@Unroll
38-
def "Date parse literal #literal.value as #result"() {
39-
expect:
40-
new GraphqlDateCoercing().parseLiteral(literal) == result
41-
42-
where:
43-
literal | result
44-
new StringValue('2017-07-09T11:54:42.277Z') | createDate(2017, 7, 9, 11, 54, 42, 277)
45-
new StringValue('2017-07-09T13:14:45.947Z') | createDate(2017, 7, 9, 13, 14, 45, 947)
46-
new StringValue('2017-07-09T11:54:42Z') | createDate(2017, 7, 9, 11, 54, 42)
47-
new StringValue('2017-07-09') | createDate(2017, 7, 9)
48-
}
59+
/*
60+
@Unroll
61+
def "Date parseLiteral throws exception for invalid #literal"() {
62+
when:
63+
new GraphqlDateCoercing().parseLiteral(literal)
4964
50-
@Unroll
51-
def "Date parseLiteral throws exception for invalid #literal"() {
52-
when:
53-
new GraphqlDateCoercing().parseLiteral(literal)
65+
then:
66+
thrown(CoercingParseLiteralException)
5467
55-
then:
56-
thrown(CoercingParseLiteralException)
68+
where:
69+
literal | _
70+
new StringValue('') | _
71+
new StringValue('not a date') | _
72+
}
5773
58-
where:
59-
literal | _
60-
new StringValue('') | _
61-
new StringValue('not a date') | _
62-
}
74+
@Unroll
75+
def "Date serialize #value into #result (#result.class)"() {
76+
expect:
77+
new GraphqlDateCoercing().serialize(value) == result
78+
79+
where:
80+
value | result
81+
createDate(2017, 7, 9, 11, 54, 42, 277) | '2017-07-09T11:54:42.277Z'
82+
createDate(2017, 7, 9, 13, 14, 45, 947) | '2017-07-09T13:14:45.947Z'
83+
createDate(2017, 7, 9, 11, 54, 42) | '2017-07-09T11:54:42Z'
84+
createDate(2017, 7, 9) | '2017-07-09T00:00:00Z'
85+
}
6386
64-
@Unroll
65-
def "Date serialize #value into #result (#result.class)"() {
66-
expect:
67-
new GraphqlDateCoercing().serialize(value) == result
68-
69-
where:
70-
value | result
71-
createDate(2017, 7, 9, 11, 54, 42, 277) | '2017-07-09T11:54:42.277Z'
72-
createDate(2017, 7, 9, 13, 14, 45, 947) | '2017-07-09T13:14:45.947Z'
73-
createDate(2017, 7, 9, 11, 54, 42) | '2017-07-09T11:54:42Z'
74-
createDate(2017, 7, 9) | '2017-07-09T00:00:00Z'
75-
}
87+
@Unroll
88+
def "serialize throws exception for invalid input #value"() {
89+
when:
90+
new GraphqlDateCoercing().serialize(value)
91+
then:
92+
thrown(CoercingSerializeException)
93+
94+
where:
95+
value | _
96+
'' | _
97+
'not a date' | _
98+
new Object() | _
99+
}
76100
77-
@Unroll
78-
def "serialize throws exception for invalid input #value"() {
79-
when:
80-
new GraphqlDateCoercing().serialize(value)
81-
then:
82-
thrown(CoercingSerializeException)
83-
84-
where:
85-
value | _
86-
'' | _
87-
'not a date' | _
88-
new Object() | _
89-
}
101+
@Unroll
102+
def "Date parse #value into #result (#result.class)"() {
103+
expect:
104+
new GraphqlDateCoercing().parseValue(value) == result
105+
106+
where:
107+
value | result
108+
'2017-07-09T11:54:42.277Z' | createDate(2017, 7, 9, 11, 54, 42, 277)
109+
'2017-07-09T13:14:45.947Z' | createDate(2017, 7, 9, 13, 14, 45, 947)
110+
'2017-07-09T11:54:42Z' | createDate(2017, 7, 9, 11, 54, 42)
111+
'2017-07-09' | createDate(2017, 7, 9)
112+
}
90113
91-
@Unroll
92-
def "Date parse #value into #result (#result.class)"() {
93-
expect:
94-
new GraphqlDateCoercing().parseValue(value) == result
95-
96-
where:
97-
value | result
98-
'2017-07-09T11:54:42.277Z' | createDate(2017, 7, 9, 11, 54, 42, 277)
99-
'2017-07-09T13:14:45.947Z' | createDate(2017, 7, 9, 13, 14, 45, 947)
100-
'2017-07-09T11:54:42Z' | createDate(2017, 7, 9, 11, 54, 42)
101-
'2017-07-09' | createDate(2017, 7, 9)
102-
}
114+
@Unroll
115+
def "parseValue throws exception for invalid input #value"() {
116+
when:
117+
new GraphqlDateCoercing().parseValue(value)
118+
then:
119+
thrown(CoercingParseValueException)
120+
121+
where:
122+
value | _
123+
'' | _
124+
'not a date' | _
125+
new Object() | _
126+
}
127+
*/
103128

104-
@Unroll
105-
def "parseValue throws exception for invalid input #value"() {
106-
when:
107-
new GraphqlDateCoercing().parseValue(value)
108-
then:
109-
thrown(CoercingParseValueException)
110-
111-
where:
112-
value | _
113-
'' | _
114-
'not a date' | _
115-
new Object() | _
129+
}) {
130+
131+
init {
132+
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
116133
}
117134

118135
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
22+
import io.kotest.core.spec.style.FunSpec
2423

2524
import java.time.Duration
2625

27-
import static java.time.ZoneOffset.UTC
26+
import java.time.ZoneOffset.UTC
2827

2928
/**
3029
* @author Alexey Zhokhov
3130
*
3231
* Test Java 8 ISO 8601 Duration
3332
*/
34-
class GraphQLDurationTest extends Specification {
33+
class GraphQLDurationTest : FunSpec({
3534

35+
/*
3636
def setup() {
3737
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
3838
}
@@ -114,5 +114,6 @@ class GraphQLDurationTest extends Specification {
114114
'1DT3H' | _
115115
new Object() | _
116116
}
117+
*/
117118

118-
}
119+
})

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
22+
import io.kotest.core.spec.style.FunSpec
2423

2524
import java.time.LocalDate
2625
import java.time.ZoneOffset
2726
import java.time.format.DateTimeFormatter
2827

29-
import static java.time.ZoneOffset.UTC
30-
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE
28+
import java.time.ZoneOffset.UTC
29+
import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE
3130

3231
/**
3332
* @author Alexey Zhokhov
3433
*/
35-
class GraphQLLocalDateTest extends Specification {
34+
class GraphQLLocalDateTest : FunSpec({
3635

36+
/*
3737
def setup() {
3838
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
3939
}
@@ -149,5 +149,6 @@ class GraphQLLocalDateTest extends Specification {
149149
value | result
150150
LocalDate.of(2020, 7, 6) | '07/06/2020'
151151
}
152+
*/
152153

153-
}
154+
})

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
22+
import io.kotest.core.spec.style.FunSpec
2423

2524
import java.time.LocalDate
2625
import java.time.LocalDateTime
2726
import java.time.LocalTime
2827
import java.time.ZoneOffset
2928
import java.time.format.DateTimeFormatter
3029

31-
import static java.time.ZoneOffset.UTC
32-
import static java.time.format.DateTimeFormatter.ISO_INSTANT
33-
import static java.util.concurrent.TimeUnit.MILLISECONDS
30+
import java.time.ZoneOffset.UTC
31+
import java.time.format.DateTimeFormatter.ISO_INSTANT
32+
import java.util.concurrent.TimeUnit.MILLISECONDS
3433

3534
/**
3635
* @author Alexey Zhokhov
3736
*/
38-
class GraphQLLocalDateTimeTest extends Specification {
37+
class GraphQLLocalDateTimeTest : FunSpec({
3938

39+
/*
4040
def setup() {
4141
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
4242
}
@@ -183,5 +183,6 @@ class GraphQLLocalDateTimeTest extends Specification {
183183
value | result
184184
LocalDateTime.of(1993, 2, 9, 13, 15, 59) | '1993-02-09T13:15:59'
185185
}
186+
*/
186187

187-
}
188+
})

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
22+
import io.kotest.core.spec.style.FunSpec
2423

2524
import java.time.LocalTime
2625
import java.util.concurrent.TimeUnit
2726

28-
import static java.time.ZoneOffset.UTC
27+
import java.time.ZoneOffset.UTC
2928

3029
/**
3130
* @author Alexey Zhokhov
3231
*/
33-
class GraphQLLocalTimeTest extends Specification {
32+
class GraphQLLocalTimeTest : FunSpec({
3433

34+
/*
3535
def setup() {
3636
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
3737
}
@@ -115,5 +115,6 @@ class GraphQLLocalTimeTest extends Specification {
115115
'not a localtime' | _
116116
new Object() | _
117117
}
118+
*/
118119

119-
}
120+
})

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ import graphql.language.StringValue
1919
import graphql.schema.CoercingParseLiteralException
2020
import graphql.schema.CoercingParseValueException
2121
import graphql.schema.CoercingSerializeException
22-
import spock.lang.Specification
23-
import spock.lang.Unroll
22+
import io.kotest.core.spec.style.FunSpec
2423

2524
import java.time.YearMonth
2625

27-
import static java.time.ZoneOffset.UTC
26+
import java.time.ZoneOffset.UTC
2827

2928
/**
3029
* @author Alexey Zhokhov
3130
*/
32-
class GraphQLYearMonthTest extends Specification {
31+
class GraphQLYearMonthTest : FunSpec({
3332

33+
/*
3434
def setup() {
3535
TimeZone.setDefault(TimeZone.getTimeZone(UTC))
3636
}
@@ -112,5 +112,6 @@ class GraphQLYearMonthTest extends Specification {
112112
'not a date' | _
113113
new Object() | _
114114
}
115+
*/
115116

116-
}
117+
})

0 commit comments

Comments
 (0)