Skip to content

Commit af8bec7

Browse files
committed
rework other methods to junit
1 parent b13a009 commit af8bec7

File tree

1 file changed

+62
-79
lines changed

1 file changed

+62
-79
lines changed
Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package org.unbrokendome.gradle.pluginutils
22

33
import assertk.assertThat
4-
import assertk.assertions.*
5-
import io.kotest.core.spec.style.DescribeSpec
6-
import io.kotest.data.Headers2
7-
import io.kotest.data.Row2
8-
import io.kotest.data.Table2
9-
import io.kotest.data.forAll
4+
import assertk.assertions.hasMessage
5+
import assertk.assertions.isEqualTo
6+
import assertk.assertions.isFailure
7+
import assertk.assertions.isInstanceOf
8+
import assertk.assertions.isNotNull
9+
import assertk.assertions.isSuccess
1010
import io.mockk.mockk
1111
import io.mockk.verify
1212
import org.gradle.util.GradleVersion
1313
import org.junit.jupiter.api.Test
1414
import org.junit.jupiter.params.ParameterizedTest
1515
import org.junit.jupiter.params.provider.MethodSource
16-
import org.junit.jupiter.params.provider.ValueSource
1716
import kotlin.reflect.full.memberProperties
1817

1918
class GradleVersionsTest {
2019

2120
data class VersionInput(val major: Int, val minor: Int)
2221

2322
companion object {
23+
val veryHighVersion = GradleVersion.version("9999.99")!!
24+
2425
@JvmStatic
25-
fun versionsInput() : List<VersionInput> {
26+
fun versionsInput(): List<VersionInput> {
2627
return listOf(
2728
4 to 0..10,
2829
5 to 0..6,
@@ -50,94 +51,76 @@ class GradleVersionsTest {
5051
.transform { it.get(GradleVersions) }
5152
.isEqualTo(version)
5253
}
53-
}
54-
55-
56-
class GradleVersionsTestOld : DescribeSpec({
57-
val veryHighVersion = GradleVersion.version("9999.99")
58-
59-
60-
describe("checkGradleVersion with message") {
61-
62-
it("should return normally if the version is ok") {
63-
assertThat {
64-
checkGradleVersion(GradleVersions.Version_6_2) { "version too low" }
65-
}.isSuccess()
66-
}
6754

68-
it("should throw an exception if the version is too low") {
69-
assertThat {
70-
checkGradleVersion(veryHighVersion) { "version too low" }
71-
}.isFailure()
72-
.isInstanceOf(IllegalStateException::class)
73-
.hasMessage("version too low")
74-
}
55+
@Test
56+
fun `checkGradleVersion with message should return normally if the version is ok`() {
57+
assertThat {
58+
checkGradleVersion(GradleVersions.Version_6_2) { "version too low" }
59+
}.isSuccess()
7560
}
7661

77-
78-
describe("checkGradleVersion with plugin ID") {
79-
80-
it("should return normally if the version is ok") {
81-
assertThat {
82-
checkGradleVersion(GradleVersions.Version_6_2, "test.plugin")
83-
}.isSuccess()
84-
}
85-
86-
it("should throw an exception if the version is too low") {
87-
assertThat {
88-
checkGradleVersion(veryHighVersion, "test.plugin")
89-
}.isFailure()
90-
.isInstanceOf(IllegalStateException::class)
91-
.hasMessage("The plugin \"test.plugin\" requires at least Gradle 9999.99")
92-
}
62+
@Test
63+
fun `should throw an exception if the version is too low`() {
64+
assertThat {
65+
checkGradleVersion(veryHighVersion) { "version too low" }
66+
}.isFailure()
67+
.isInstanceOf(IllegalStateException::class)
68+
.hasMessage("version too low")
9369
}
9470

71+
@Test
72+
fun `checkGradleVersion with plugin ID should return normally if the version is ok`() {
73+
assertThat {
74+
checkGradleVersion(GradleVersions.Version_6_2, "test.plugin")
75+
}.isSuccess()
76+
}
9577

96-
describe("withMinGradleVersion") {
97-
98-
it("should execute the block if the version is ok") {
99-
100-
val block = mockk<Runnable>(relaxed = true)
101-
102-
withMinGradleVersion(GradleVersions.Version_6_2, block::run)
103-
104-
verify(exactly = 1) { block.run() }
105-
}
106-
107-
108-
it("should not execute the block if the version is too low") {
78+
@Test
79+
fun `checkGradleVersion with plugin ID should throw an exception if the version is too low`() {
80+
assertThat {
81+
checkGradleVersion(veryHighVersion, "test.plugin")
82+
}.isFailure()
83+
.isInstanceOf(IllegalStateException::class)
84+
.hasMessage("The plugin \"test.plugin\" requires at least Gradle 9999.99")
85+
}
10986

110-
val block = mockk<Runnable>(relaxed = true)
87+
@Test
88+
fun `withMinGradleVersion should execute the block if the version is ok`() {
89+
val block = mockk<Runnable>(relaxed = true)
11190

112-
withMinGradleVersion(veryHighVersion, block::run)
91+
withMinGradleVersion(GradleVersions.Version_6_2, block::run)
11392

114-
verify(exactly = 0) { block.run() }
115-
}
93+
verify(exactly = 1) { block.run() }
11694
}
11795

96+
@Test
97+
fun `withMinGradleVersion should not execute the block if the version is too low`() {
98+
val block = mockk<Runnable>(relaxed = true)
11899

119-
describe("withMinGradleVersion with fallback") {
100+
withMinGradleVersion(veryHighVersion, block::run)
120101

121-
it("should execute the block if the version is ok") {
102+
verify(exactly = 0) { block.run() }
103+
}
122104

123-
val block = mockk<Runnable>("block", relaxed = true)
124-
val fallback = mockk<Runnable>("fallback", relaxed = true)
105+
@Test
106+
fun `withMinGradleVersion with fallback should execute the block if the version is ok`() {
107+
val block = mockk<Runnable>("block", relaxed = true)
108+
val fallback = mockk<Runnable>("fallback", relaxed = true)
125109

126-
withMinGradleVersion(GradleVersions.Version_6_2, block::run, fallback::run)
110+
withMinGradleVersion(GradleVersions.Version_6_2, block::run, fallback::run)
127111

128-
verify(exactly = 1) { block.run() }
129-
verify(exactly = 0) { fallback.run() }
130-
}
131-
132-
it("should execute the fallback if the version is too low") {
112+
verify(exactly = 1) { block.run() }
113+
verify(exactly = 0) { fallback.run() }
114+
}
133115

134-
val block = mockk<Runnable>("block", relaxed = true)
135-
val fallback = mockk<Runnable>("fallback", relaxed = true)
116+
@Test
117+
fun `withMinGradleVersion with fallback should execute the fallback if the version is too low`() {
118+
val block = mockk<Runnable>("block", relaxed = true)
119+
val fallback = mockk<Runnable>("fallback", relaxed = true)
136120

137-
withMinGradleVersion(veryHighVersion, block::run, fallback::run)
121+
withMinGradleVersion(veryHighVersion, block::run, fallback::run)
138122

139-
verify(exactly = 0) { block.run() }
140-
verify(exactly = 1) { fallback.run() }
141-
}
123+
verify(exactly = 0) { block.run() }
124+
verify(exactly = 1) { fallback.run() }
142125
}
143-
})
126+
}

0 commit comments

Comments
 (0)