Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
add find system by type method
Browse files Browse the repository at this point in the history
  • Loading branch information
Adven27 committed Oct 1, 2021
1 parent 9f89f3b commit fbb5e8f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ open class Environment @JvmOverloads constructor(

@Suppress("UNCHECKED_CAST")
fun <T : ExternalSystem> find(name: String): T = (systems[name] ?: error("System $name not found")) as T
inline fun <reified T : ExternalSystem> find() = systems.values.filterIsInstance<T>().single()

companion object : KLogging() {
private fun start(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class EmbeddedKafkaSystemTest {
}

class SomeEnvironment : Environment("EMBEDDED_KAFKA" to EmbeddedKafkaSystem("some-topic")) {
fun kafka() = find<EmbeddedKafkaSystem>("EMBEDDED_KAFKA")
fun kafka() = find<EmbeddedKafkaSystem>()
}
4 changes: 2 additions & 2 deletions example/src/test/kotlin/EnvTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ class SomeEnvironment : Environment(
},
"WIREMOCK" to WiremockSystem()
) {
fun rabbit() = find<RabbitContainerSystem>("RABBIT")
fun postgres() = systems["POSTGRES"] as PostgreSqlContainerSystem
fun rabbit() = find<RabbitContainerSystem>()
fun postgres() = find<PostgreSqlContainerSystem>()
}

0 comments on commit fbb5e8f

Please sign in to comment.