From f3d9750ea5d6e0129347f9a63d67e0e5216067ac Mon Sep 17 00:00:00 2001 From: Dominic Fox Date: Thu, 19 Jul 2018 13:47:18 +0100 Subject: [PATCH] Eliminate needless equalTo --- .../net/corda/core/flows/ReceiveAllFlowTests.kt | 6 +++--- .../net/corda/core/flows/matchers/FutureMatchers.kt | 7 +++++-- .../corda/core/flows/matchers/flow/FlowMatchers.kt | 11 ++++++----- .../net/corda/core/flows/matchers/rpc/RpcMatchers.kt | 8 +++----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt index 903fd8d674..3ae1c87b9d 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt @@ -60,7 +60,7 @@ class ReceiveMultipleFlowTests : WithMockNet { assert.that( nodes[0].startFlowAndRunNetwork(initiatingFlow), - willReturn(isA(equalTo(answer)))) + willReturn(answer as Any)) } @Test @@ -72,7 +72,7 @@ class ReceiveMultipleFlowTests : WithMockNet { assert.that( nodes[0].startFlowAndRunNetwork(ParallelAlgorithmMap(nodes[1].info.singleIdentity(), nodes[2].info.singleIdentity())), - willReturn(equalTo(doubleValue * stringValue.length))) + willReturn(doubleValue * stringValue.length)) } @Test @@ -84,7 +84,7 @@ class ReceiveMultipleFlowTests : WithMockNet { assert.that( nodes[0].startFlowAndRunNetwork(ParallelAlgorithmList(nodes[1].info.singleIdentity(), nodes[2].info.singleIdentity())), - willReturn(equalTo(listOf(value1, value2)))) + willReturn(listOf(value1, value2))) } class ParallelAlgorithmMap(doubleMember: Party, stringMember: Party) : AlgorithmDefinition(doubleMember, stringMember) { diff --git a/core/src/test/kotlin/net/corda/core/flows/matchers/FutureMatchers.kt b/core/src/test/kotlin/net/corda/core/flows/matchers/FutureMatchers.kt index 13c9dc96f8..dd0edc4747 100644 --- a/core/src/test/kotlin/net/corda/core/flows/matchers/FutureMatchers.kt +++ b/core/src/test/kotlin/net/corda/core/flows/matchers/FutureMatchers.kt @@ -2,6 +2,7 @@ package net.corda.core.flows.matchers import com.natpryce.hamkrest.MatchResult import com.natpryce.hamkrest.Matcher +import com.natpryce.hamkrest.equalTo import net.corda.core.utilities.getOrThrow import java.util.concurrent.Future @@ -19,10 +20,12 @@ fun willReturn() = object : Matcher> { } } +fun willReturn(expected: T): Matcher> = willReturn(equalTo(expected)) + /** * Matches a Flow that succeeds with a result matched by the given matcher */ -fun willSucceedWithResult(successMatcher: Matcher) = object : Matcher> { +fun willReturn(successMatcher: Matcher) = object : Matcher> { override val description: String = "is a future that will succeed with a value that ${successMatcher.description}" override fun invoke(actual: Future): MatchResult = try { @@ -35,7 +38,7 @@ fun willSucceedWithResult(successMatcher: Matcher) = object : Matcher willFailWithException(failureMatcher: Matcher) = object : Matcher> { +inline fun willThrow(failureMatcher: Matcher) = object : Matcher> { override val description: String get() = "is a future that will fail with a ${E::class.java.simpleName} that ${failureMatcher.description}" diff --git a/core/src/test/kotlin/net/corda/core/flows/matchers/flow/FlowMatchers.kt b/core/src/test/kotlin/net/corda/core/flows/matchers/flow/FlowMatchers.kt index f9af1194dc..afd298c7bc 100644 --- a/core/src/test/kotlin/net/corda/core/flows/matchers/flow/FlowMatchers.kt +++ b/core/src/test/kotlin/net/corda/core/flows/matchers/flow/FlowMatchers.kt @@ -1,11 +1,10 @@ package net.corda.core.flows.matchers.flow import com.natpryce.hamkrest.Matcher +import com.natpryce.hamkrest.equalTo import com.natpryce.hamkrest.has -import net.corda.core.flows.matchers.willFailWithException -import net.corda.core.flows.matchers.willReturn -import net.corda.core.flows.matchers.willSucceedWithResult import net.corda.core.flows.matchers.willThrow +import net.corda.core.flows.matchers.willReturn import net.corda.core.internal.FlowStateMachine /** @@ -13,19 +12,21 @@ import net.corda.core.internal.FlowStateMachine */ fun willReturn() = has(FlowStateMachine::resultFuture, willReturn()) +fun willReturn(expected: T): Matcher> = net.corda.core.flows.matchers.flow.willReturn(equalTo(expected)) + /** * Matches a Flow that succeeds with a result matched by the given matcher */ fun willReturn(successMatcher: Matcher) = has( FlowStateMachine::resultFuture, - willSucceedWithResult(successMatcher)) + willReturn(successMatcher)) /** * Matches a Flow that fails, with an exception matched by the given matcher. */ inline fun willThrow(failureMatcher: Matcher) = has( FlowStateMachine<*>::resultFuture, - willFailWithException(failureMatcher)) + willThrow(failureMatcher)) /** * Matches a Flow that fails, with an exception of the specified type. diff --git a/core/src/test/kotlin/net/corda/core/flows/matchers/rpc/RpcMatchers.kt b/core/src/test/kotlin/net/corda/core/flows/matchers/rpc/RpcMatchers.kt index 8f5803a409..69d59c5c68 100644 --- a/core/src/test/kotlin/net/corda/core/flows/matchers/rpc/RpcMatchers.kt +++ b/core/src/test/kotlin/net/corda/core/flows/matchers/rpc/RpcMatchers.kt @@ -2,10 +2,8 @@ package net.corda.core.flows.matchers.rpc import com.natpryce.hamkrest.Matcher import com.natpryce.hamkrest.has -import net.corda.core.flows.matchers.willFailWithException -import net.corda.core.flows.matchers.willReturn -import net.corda.core.flows.matchers.willSucceedWithResult import net.corda.core.flows.matchers.willThrow +import net.corda.core.flows.matchers.willReturn import net.corda.core.messaging.FlowHandle /** @@ -16,14 +14,14 @@ fun willReturn() = has(FlowHandle::returnValue, willReturn()) /** * Matches a flow handle that succeeds with a result matched by the given matcher */ -fun willReturn(successMatcher: Matcher) = has(FlowHandle::returnValue, willSucceedWithResult(successMatcher)) +fun willReturn(successMatcher: Matcher) = has(FlowHandle::returnValue, willReturn(successMatcher)) /** * Matches a flow handle that fails, with an exception matched by the given matcher. */ inline fun willThrow(failureMatcher: Matcher) = has( FlowHandle<*>::returnValue, - willFailWithException(failureMatcher)) + willThrow(failureMatcher)) /** * Matches a flow handle that fails, with an exception of the specified type.