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 18, 2021
1 parent fbb5e8f commit 0c3b78b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ open class Environment @JvmOverloads constructor(
"\n\n ==================================================\n\n"

@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()
fun <T : ExternalSystem> env(name: String): T = (systems[name] ?: error("System $name not found")) as T
inline fun <reified T : ExternalSystem> env() = 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 @@ -31,7 +31,7 @@ open class EmbeddedKafkaSystem(
CONTROLLED_SHUTDOWN,
NUMBER_OF_PARTITIONS,
*topics
).brokerProperties(properties),
).brokerProperties(mapOf("group.initial.rebalance.delay.ms" to "0") + properties),
defaultPort
)

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>()
fun kafka() = env<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>()
fun postgres() = find<PostgreSqlContainerSystem>()
fun rabbit() = env<RabbitContainerSystem>()
fun postgres() = env<PostgreSqlContainerSystem>()
}

0 comments on commit 0c3b78b

Please sign in to comment.