Skip to content

Commit

Permalink
Add a test to show support for Kotlin @JvmInline value classes as @Te…
Browse files Browse the repository at this point in the history
…stParameter field parameters

It doesn't work by string parsing though. I think this is almost impossible to fix because the Kotlin field has the wrapper type instead of the wrapped type when requested via reflection.

Related to #22.
  • Loading branch information
nymanjens committed Oct 26, 2022
1 parent ea2ccf7 commit 8ace594
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.testing.junit.testparameterinjector
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableMap
import com.google.testing.junit.testparameterinjector.SharedTestUtilitiesJUnit4.SuccessfulTestCaseBase
import com.google.testing.junit.testparameterinjector.TestParameter.TestParameterValuesProvider
import java.util.Arrays
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -130,6 +131,30 @@ class TestParameterInjectorKotlinTest {
}
}

@RunAsTest
internal class TestParameter_Field_WithValueClass : SuccessfulTestCaseBase() {
@TestParameter(valuesProvider = DoubleValueClassProvider::class)
var width: DoubleValueClass? = null

@Test
fun test() {
storeTestParametersForThisTest(width?.onlyValue)
}

override fun expectedTestNameToStringifiedParameters(): ImmutableMap<String, String> {
return ImmutableMap.builder<String, String>()
.put("test[DoubleValueClass(onlyValue=1.0)]", "1.0")
.put("test[DoubleValueClass(onlyValue=2.5)]", "2.5")
.buildOrThrow()
}

private class DoubleValueClassProvider : TestParameterValuesProvider {
override fun provideValues(): List<DoubleValueClass> {
return ImmutableList.of(DoubleValueClass(1.0), DoubleValueClass(2.5))
}
}
}

@RunAsTest
internal class TestParameter_ConstructorParam : SuccessfulTestCaseBase {
val width: Int
Expand Down

0 comments on commit 8ace594

Please sign in to comment.