From d19e8b6a7b3b5cc63b9fb8b77e87c68d87fbbb99 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Thu, 8 Sep 2016 16:09:33 +0100 Subject: [PATCH] test-utils: Remove unnecessary type variable from Expect functions, fixes compile error --- .../main/kotlin/com/r3corda/testing/Expect.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test-utils/src/main/kotlin/com/r3corda/testing/Expect.kt b/test-utils/src/main/kotlin/com/r3corda/testing/Expect.kt index 3fb86fdcea..7441ea5246 100644 --- a/test-utils/src/main/kotlin/com/r3corda/testing/Expect.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/Expect.kt @@ -41,22 +41,25 @@ private val log: Logger = LoggerFactory.getLogger("Expect") * @param match Optional additional matching logic * @param expectClosure The closure to run on the event */ -fun expect(klass: Class, match: (T) -> Boolean, expectClosure: (T) -> Unit): ExpectCompose { +fun expect(klass: Class, match: (E) -> Boolean, expectClosure: (E) -> Unit): ExpectCompose { return ExpectCompose.Single(Expect(klass, match, expectClosure)) } /** * Convenience variant of [expect] reifying the [Class] parameter */ -inline fun expect( - noinline match: (T) -> Boolean = { true }, - noinline expectClosure: (T) -> Unit = {} -): ExpectCompose = expect(T::class.java, match, expectClosure) +inline fun expect( + noinline match: (E) -> Boolean = { true }, + noinline expectClosure: (E) -> Unit +): ExpectCompose = expect(E::class.java, match, expectClosure) /** * Convenience variant of [expect] that only matches events that are strictly equal to [event] */ -inline fun expect(event: E): ExpectCompose = expect(match = { event == it }) +inline fun expect( + event: E, + noinline expectClosure: (E) -> Unit = {} +): ExpectCompose = expect(match = { event == it }, expectClosure = expectClosure) /** * Tests that events arrive in the specified order. @@ -78,7 +81,8 @@ fun parallel(vararg expectations: ExpectCompose): ExpectCompose = Expe * @param number The number of events expected. * @param expectation The piece of DSL to run on each event, with the index of the event passed in. */ -inline fun replicate(number: Int, expectation: (Int) -> ExpectCompose) = sequence(*Array(number) { expectation(it) }) +inline fun replicate(number: Int, expectation: (Int) -> ExpectCompose): ExpectCompose = + sequence(*Array(number) { expectation(it) }) /** * Run the specified DSL against the event [Observable]. @@ -163,25 +167,25 @@ fun S.genericExpectEvents( } sealed class ExpectCompose { - internal class Single(val expect: Expect) : ExpectCompose() + internal class Single(val expect: Expect) : ExpectCompose() internal class Sequential(val sequence: List>) : ExpectCompose() internal class Parallel(val parallel: List>) : ExpectCompose() } -internal data class Expect( - val clazz: Class, - val match: (T) -> Boolean, - val expectClosure: (T) -> Unit +internal data class Expect( + val clazz: Class, + val match: (E) -> Boolean, + val expectClosure: (E) -> Unit ) private sealed class ExpectComposeState { abstract fun nextState(event: E): Pair<() -> Unit, ExpectComposeState>? - abstract fun getExpectedEvents(): List> + abstract fun getExpectedEvents(): List> class Finished : ExpectComposeState() { override fun nextState(event: E) = null - override fun getExpectedEvents(): List> = listOf() + override fun getExpectedEvents(): List> = listOf() } class Single(val single: ExpectCompose.Single) : ExpectComposeState() { override fun nextState(event: E): Pair<() -> Unit, ExpectComposeState>? =