Skip to content

Commit 30936ca

Browse files
committed
Restructure Kotlin tests, add DisplayNameGenerator
1 parent b5b86cc commit 30936ca

6 files changed

Lines changed: 81 additions & 8 deletions

File tree

assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/Assertions_assertThat_Test.kt renamed to assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/api/Assertions_assertThat_Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*
1111
* Copyright 2012-2025 the original author or authors.
1212
*/
13-
package org.assertj.tests.core.kotlin
13+
package org.assertj.tests.core.kotlin.api
1414

1515
import org.assertj.core.api.Assertions.assertThat
1616
import org.junit.jupiter.api.Test
1717

18-
internal class Assertions_assertThat_Test {
18+
class Assertions_assertThat_Test {
1919

2020
@Test
2121
fun intarray() {

assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/Assertions_catchThrowableOfType_Test.kt renamed to assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/api/Assertions_catchThrowableOfType_Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*
1111
* Copyright 2012-2025 the original author or authors.
1212
*/
13-
package org.assertj.tests.core.kotlin
13+
package org.assertj.tests.core.kotlin.api
1414

1515
import org.assertj.core.api.Assertions.catchThrowableOfType
1616
import org.assertj.core.api.BDDAssertions.then
1717
import org.junit.jupiter.api.Test
1818

19-
internal class Assertions_catchThrowableOfType_Test {
19+
class Assertions_catchThrowableOfType_Test {
2020

2121
@Test
2222
fun `should work with lambda expressions`() {

assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/Assertions_describedAs_text_supplier_Test.kt renamed to assertj-tests/assertj-integration-tests/assertj-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/api/abstract_/AbstractAssert_as_with_description_text_supplier_Test.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*
1111
* Copyright 2012-2025 the original author or authors.
1212
*/
13-
package org.assertj.tests.core.kotlin
13+
package org.assertj.tests.core.kotlin.api.abstract_
1414

15-
import org.assertj.core.api.Assertions
1615
import org.assertj.core.api.Assertions.assertThat
16+
import org.assertj.core.api.Assertions.catchThrowable
1717
import org.assertj.core.api.BDDAssertions.then
1818
import org.assertj.tests.core.kotlin.testkit.AssertionsUtil.expectAssertionError
1919
import org.assertj.tests.core.kotlin.testkit.ConcreteAssert
@@ -25,7 +25,7 @@ import java.util.function.Supplier
2525
* See [org.assertj.core.api.abstract_.AbstractAssert_as_with_description_text_supplier_Test].
2626
* `as` is a keyword in Kotlin, so we use `describedAs` instead.
2727
*/
28-
internal class Assertions_describedAs_text_supplier_Test {
28+
class AbstractAssert_as_with_description_text_supplier_Test {
2929

3030
@Test
3131
fun `descriptionText should evaluate lazy description`() {
@@ -77,7 +77,7 @@ internal class Assertions_describedAs_text_supplier_Test {
7777
val assertions = ConcreteAssert("foo")
7878
val descriptionSupplier: Supplier<String>? = null
7979
// WHEN
80-
val throwable = Assertions.catchThrowable {
80+
val throwable = catchThrowable {
8181
assertions.describedAs(
8282
descriptionSupplier
8383
).descriptionText()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2025 the original author or authors.
12+
*/
13+
package org.assertj.tests.core.kotlin.testkit.junit.jupiter
14+
15+
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores
16+
17+
private const val TEST_SUFFIX = " Test"
18+
19+
class DefaultDisplayNameGenerator : ReplaceUnderscores() {
20+
21+
override fun generateDisplayNameForClass(testClass: Class<*>?): String {
22+
return removeTestSuffixIfExists(super.generateDisplayNameForClass(testClass))
23+
}
24+
25+
private fun removeTestSuffixIfExists(displayName: String): String {
26+
return if (displayName.endsWith(TEST_SUFFIX))
27+
displayName.substring(0, displayName.lastIndexOf(TEST_SUFFIX))
28+
else
29+
displayName
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2025 the original author or authors.
12+
*/
13+
package org.assertj.tests.core.kotlin.testkit.junit.jupiter
14+
15+
import org.assertj.core.api.BDDAssertions.then
16+
import org.junit.jupiter.params.ParameterizedTest
17+
import org.junit.jupiter.params.provider.CsvSource
18+
19+
class DefaultDisplayNameGeneratorTest {
20+
21+
private val underTest = DefaultDisplayNameGenerator()
22+
23+
@ParameterizedTest
24+
@CsvSource(
25+
"org.assertj.tests.core.kotlin.testkit.junit.jupiter.SomeAssert_someMethod_Test, SomeAssert someMethod",
26+
"org.assertj.tests.core.kotlin.testkit.junit.jupiter.SomeAssert_someMethod_with_SomeType_Test, SomeAssert someMethod with SomeType"
27+
)
28+
fun generateDisplayNameForClass_should_remove_test_suffix(testClass: Class<*>?, expected: String?) {
29+
// WHEN
30+
val displayName = underTest.generateDisplayNameForClass(testClass)
31+
// THEN
32+
then(displayName).isEqualTo(expected)
33+
}
34+
}
35+
36+
@Suppress("unused")
37+
internal class SomeAssert_someMethod_Test
38+
39+
@Suppress("unused")
40+
internal class SomeAssert_someMethod_with_SomeType_Test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
junit.jupiter.displayname.generator.default=org.assertj.tests.core.kotlin.testkit.junit.jupiter.DefaultDisplayNameGenerator

0 commit comments

Comments
 (0)