mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
Added ServiceInfo unit tests
This commit is contained in:
parent
5efa0fd5b3
commit
62a9dfe900
@ -11,8 +11,10 @@ data class ServiceInfo(val type: ServiceType, val name: String? = null) {
|
||||
companion object {
|
||||
fun parse(encoded: String): ServiceInfo {
|
||||
val parts = encoded.split("|")
|
||||
require(parts.size > 0 && parts.size <= 2)
|
||||
return ServiceInfo(object : ServiceType(parts[0]) {}, parts[1])
|
||||
require(parts.size > 0 && parts.size <= 2) { "Invalid number of elements found" }
|
||||
val type = object : ServiceType(parts[0]) {}
|
||||
val name = parts.getOrNull(1)
|
||||
return ServiceInfo(type, name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.r3corda.core.node
|
||||
|
||||
import com.r3corda.core.node.services.ServiceInfo
|
||||
import com.r3corda.core.node.services.ServiceType
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class ServiceInfoTests {
|
||||
val serviceType = object : ServiceType("corda.service.subservice") {}
|
||||
val name = "service.name"
|
||||
|
||||
@Test
|
||||
fun `type and name encodes correctly`() {
|
||||
assertEquals(ServiceInfo(serviceType, name).toString(), "$serviceType|$name")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `type and name parses correctly`() {
|
||||
assertEquals(ServiceInfo.parse("$serviceType|$name"), ServiceInfo(serviceType, name))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `type only encodes correctly`() {
|
||||
assertEquals(ServiceInfo(serviceType).toString(), "$serviceType")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `type only parses correctly`() {
|
||||
assertEquals(ServiceInfo.parse("$serviceType"), ServiceInfo(serviceType))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid encoding throws`() {
|
||||
assertFailsWith<IllegalArgumentException> { ServiceInfo.parse("$serviceType|$name|something") }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user