mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Merge remote-tracking branch 'open/master' into features/ENT-1153/merge_OS2ENT
# Conflicts: # .idea/compiler.xml # docs/source/changelog.rst # node/src/test/kotlin/net/corda/node/services/transactions/DistributedImmutableMapTests.kt # testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt # testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt
This commit is contained in:
@ -131,7 +131,13 @@ private fun Config.defaultToOldPath(property: KProperty<*>): String {
|
||||
|
||||
private fun parseEnum(enumType: Class<*>, name: String): Enum<*> = enumBridge<Proxy.Type>(uncheckedCast(enumType), name) // Any enum will do
|
||||
|
||||
private fun <T : Enum<T>> enumBridge(clazz: Class<T>, name: String): T = java.lang.Enum.valueOf(clazz, name)
|
||||
private fun <T : Enum<T>> enumBridge(clazz: Class<T>, name: String): T {
|
||||
try {
|
||||
return java.lang.Enum.valueOf(clazz, name)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
throw IllegalArgumentException("$name is not one of { ${clazz.enumConstants.joinToString()} }")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the receiver object into a [Config]. This does the inverse action of [parseAs].
|
||||
|
@ -8,6 +8,7 @@ import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
@ -47,6 +48,14 @@ class ConfigParsingTest {
|
||||
testPropertyType<EnumData, EnumListData, TestEnum>(TestEnum.Value2, TestEnum.Value1, valuesToString = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unknown Enum`() {
|
||||
val config = config("value" to "UnknownValue")
|
||||
assertThatThrownBy { config.parseAs<EnumData>() }
|
||||
.hasMessageContaining(TestEnum.Value1.name)
|
||||
.hasMessageContaining(TestEnum.Value2.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `LocalDate`() {
|
||||
testPropertyType<LocalDateData, LocalDateListData, LocalDate>(LocalDate.now(), LocalDate.now().plusDays(1), valuesToString = true)
|
||||
|
Reference in New Issue
Block a user