Skip to content

Commit 239468f

Browse files
committed
Clarify generic-only inline value class support
Signed-off-by: Ogu1208 <kdasunb6@gmail.com>
1 parent f37fd16 commit 239468f

File tree

6 files changed

+97
-101
lines changed

6 files changed

+97
-101
lines changed

documentation/modules/ROOT/partials/release-notes/release-notes-6.1.0-M2.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ repository on GitHub.
5151
* Introduce new `trimStacktrace(Class<?>)` and `retainStackTraceElements(int)`
5252
methods for `AssertionFailureBuilder`. These allow user defined assertions to
5353
trim their stacktrace.
54-
* Kotlin inline value classes (such as `Result<T>`) can now be used as parameters in
55-
`@ParameterizedTest` methods when `kotlin-reflect` is on the classpath.
56-
See {junit-team-issue}5081[#5081].
54+
* Generic inline value classes (such as `kotlin.Result<T>`) can now be used as parameters
55+
in `@ParameterizedTest` methods when `kotlin-reflect` is on the classpath.
56+
Note: Primitive-wrapper inline value classes (e.g., `UInt`, custom value classes wrapping
57+
primitives) are not yet supported. See {junit-team-issue}5081[#5081].
5758

5859
[[v6.1.0-M2-junit-vintage]]
5960
=== JUnit Vintage
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.junit.jupiter.api.kotlin
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.params.ParameterizedTest
5+
import org.junit.jupiter.params.provider.Arguments
6+
import org.junit.jupiter.params.provider.MethodSource
7+
8+
/**
9+
* Tests for generic inline value classes.
10+
* These work because they compile to Object in JVM, bypassing strict type validation.
11+
*/
12+
class GenericInlineValueClassTests {
13+
14+
@MethodSource("resultProvider")
15+
@ParameterizedTest
16+
fun testResult(result: Result<String>) {
17+
assertEquals("success", result.getOrThrow())
18+
}
19+
20+
@MethodSource("multipleResultsProvider")
21+
@ParameterizedTest
22+
fun testMultipleResults(
23+
result1: Result<String>,
24+
result2: Result<Int>
25+
) {
26+
assertEquals("data", result1.getOrThrow())
27+
assertEquals(42, result2.getOrThrow())
28+
}
29+
30+
@MethodSource("nullableResultProvider")
31+
@ParameterizedTest
32+
fun testNullableResult(result: Result<String>?) {
33+
assertEquals("test", result?.getOrNull())
34+
}
35+
36+
@MethodSource("customGenericProvider")
37+
@ParameterizedTest
38+
fun testCustomGenericContainer(container: Container<String>) {
39+
assertEquals("content", container.value)
40+
}
41+
42+
companion object {
43+
@JvmStatic
44+
fun resultProvider() = listOf(
45+
Arguments.of(Result.success("success"))
46+
)
47+
48+
@JvmStatic
49+
fun multipleResultsProvider() = listOf(
50+
Arguments.of(
51+
Result.success("data"),
52+
Result.success(42)
53+
)
54+
)
55+
56+
@JvmStatic
57+
fun nullableResultProvider() = listOf(
58+
Arguments.of(Result.success("test"))
59+
)
60+
61+
@JvmStatic
62+
fun customGenericProvider() = listOf(
63+
Arguments.of(Container("content"))
64+
)
65+
}
66+
}
67+
68+
@JvmInline
69+
value class Container<T>(val value: T)

jupiter-tests/src/test/kotlin/org/junit/jupiter/api/kotlin/MultipleInlineValueClassTests.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.

jupiter-tests/src/test/kotlin/org/junit/jupiter/api/kotlin/NullableInlineValueClassTests.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.

jupiter-tests/src/test/kotlin/org/junit/jupiter/api/kotlin/CustomInlineValueClassTests.kt renamed to jupiter-tests/src/test/kotlin/org/junit/jupiter/api/kotlin/PrimitiveWrapperInlineValueClassTests.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ import org.junit.jupiter.params.provider.Arguments
77
import org.junit.jupiter.params.provider.MethodSource
88

99
/**
10-
* Tests for custom inline value classes.
10+
* Tests for primitive-wrapper inline value classes.
1111
*
12-
* Currently, disabled: The POC only supports kotlin.Result.
13-
* Support for arbitrary inline value classes needs to be added.
12+
* Currently disabled: These fail because Kotlin compiles them to primitives
13+
* (UInt→int, UserId→long), causing JUnit's type validation to fail before
14+
* reaching the invocation logic.
15+
*
16+
* Supporting these would require modifications to JUnit's core type validation system.
1417
*
1518
* @see <a href="https://github.com/junit-team/junit-framework/issues/5081">Issue #5081</a>
1619
*/
17-
@Disabled("POC only supports kotlin.Result, not custom inline value classes")
18-
class CustomInlineValueClassTests {
20+
@Disabled("Primitive-wrapper inline value classes are not yet supported")
21+
class PrimitiveWrapperInlineValueClassTests {
22+
23+
@MethodSource("uintProvider")
24+
@ParameterizedTest
25+
fun testUInt(value: UInt) {
26+
assertEquals(42u, value)
27+
}
1928

2029
@MethodSource("userIdProvider")
2130
@ParameterizedTest
@@ -30,10 +39,19 @@ class CustomInlineValueClassTests {
3039
}
3140

3241
companion object {
42+
@JvmStatic
43+
fun uintProvider() = listOf(Arguments.of(42u))
44+
3345
@JvmStatic
3446
fun userIdProvider() = listOf(Arguments.of(UserId(123L)))
3547

3648
@JvmStatic
3749
fun emailProvider() = listOf(Arguments.of(Email("test@example.com")))
3850
}
39-
}
51+
}
52+
53+
@JvmInline
54+
value class UserId(val value: Long)
55+
56+
@JvmInline
57+
value class Email(val value: String)

jupiter-tests/src/test/kotlin/org/junit/jupiter/api/kotlin/ValueClasses.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)