Eliminate needless equalTo

This commit is contained in:
Dominic Fox 2018-07-19 13:47:18 +01:00
parent c0966067cc
commit f3d9750ea5
4 changed files with 17 additions and 15 deletions

View File

@ -60,7 +60,7 @@ class ReceiveMultipleFlowTests : WithMockNet {
assert.that( assert.that(
nodes[0].startFlowAndRunNetwork(initiatingFlow), nodes[0].startFlowAndRunNetwork(initiatingFlow),
willReturn(isA(equalTo(answer)))) willReturn(answer as Any))
} }
@Test @Test
@ -72,7 +72,7 @@ class ReceiveMultipleFlowTests : WithMockNet {
assert.that( assert.that(
nodes[0].startFlowAndRunNetwork(ParallelAlgorithmMap(nodes[1].info.singleIdentity(), nodes[2].info.singleIdentity())), nodes[0].startFlowAndRunNetwork(ParallelAlgorithmMap(nodes[1].info.singleIdentity(), nodes[2].info.singleIdentity())),
willReturn(equalTo(doubleValue * stringValue.length))) willReturn(doubleValue * stringValue.length))
} }
@Test @Test
@ -84,7 +84,7 @@ class ReceiveMultipleFlowTests : WithMockNet {
assert.that( assert.that(
nodes[0].startFlowAndRunNetwork(ParallelAlgorithmList(nodes[1].info.singleIdentity(), nodes[2].info.singleIdentity())), 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) { class ParallelAlgorithmMap(doubleMember: Party, stringMember: Party) : AlgorithmDefinition(doubleMember, stringMember) {

View File

@ -2,6 +2,7 @@ package net.corda.core.flows.matchers
import com.natpryce.hamkrest.MatchResult import com.natpryce.hamkrest.MatchResult
import com.natpryce.hamkrest.Matcher import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.equalTo
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import java.util.concurrent.Future import java.util.concurrent.Future
@ -19,10 +20,12 @@ fun <T> willReturn() = object : Matcher<Future<T>> {
} }
} }
fun <T> willReturn(expected: T): Matcher<Future<out T?>> = willReturn(equalTo(expected))
/** /**
* Matches a Flow that succeeds with a result matched by the given matcher * Matches a Flow that succeeds with a result matched by the given matcher
*/ */
fun <T> willSucceedWithResult(successMatcher: Matcher<T>) = object : Matcher<Future<out T>> { fun <T> willReturn(successMatcher: Matcher<T>) = object : Matcher<Future<out T>> {
override val description: String = "is a future that will succeed with a value that ${successMatcher.description}" override val description: String = "is a future that will succeed with a value that ${successMatcher.description}"
override fun invoke(actual: Future<out T>): MatchResult = try { override fun invoke(actual: Future<out T>): MatchResult = try {
@ -35,7 +38,7 @@ fun <T> willSucceedWithResult(successMatcher: Matcher<T>) = object : Matcher<Fut
/** /**
* Matches a Flow that fails, with an exception matched by the given matcher. * Matches a Flow that fails, with an exception matched by the given matcher.
*/ */
inline fun <reified E: Exception> willFailWithException(failureMatcher: Matcher<E>) = object : Matcher<Future<*>> { inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = object : Matcher<Future<*>> {
override val description: String override val description: String
get() = "is a future that will fail with a ${E::class.java.simpleName} that ${failureMatcher.description}" get() = "is a future that will fail with a ${E::class.java.simpleName} that ${failureMatcher.description}"

View File

@ -1,11 +1,10 @@
package net.corda.core.flows.matchers.flow package net.corda.core.flows.matchers.flow
import com.natpryce.hamkrest.Matcher import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.has 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.willThrow
import net.corda.core.flows.matchers.willReturn
import net.corda.core.internal.FlowStateMachine import net.corda.core.internal.FlowStateMachine
/** /**
@ -13,19 +12,21 @@ import net.corda.core.internal.FlowStateMachine
*/ */
fun <T> willReturn() = has(FlowStateMachine<T>::resultFuture, willReturn()) fun <T> willReturn() = has(FlowStateMachine<T>::resultFuture, willReturn())
fun <T> willReturn(expected: T): Matcher<FlowStateMachine<out T?>> = net.corda.core.flows.matchers.flow.willReturn(equalTo(expected))
/** /**
* Matches a Flow that succeeds with a result matched by the given matcher * Matches a Flow that succeeds with a result matched by the given matcher
*/ */
fun <T> willReturn(successMatcher: Matcher<T>) = has( fun <T> willReturn(successMatcher: Matcher<T>) = has(
FlowStateMachine<out T>::resultFuture, FlowStateMachine<out T>::resultFuture,
willSucceedWithResult(successMatcher)) willReturn(successMatcher))
/** /**
* Matches a Flow that fails, with an exception matched by the given matcher. * Matches a Flow that fails, with an exception matched by the given matcher.
*/ */
inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has( inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has(
FlowStateMachine<*>::resultFuture, FlowStateMachine<*>::resultFuture,
willFailWithException(failureMatcher)) willThrow(failureMatcher))
/** /**
* Matches a Flow that fails, with an exception of the specified type. * Matches a Flow that fails, with an exception of the specified type.

View File

@ -2,10 +2,8 @@ package net.corda.core.flows.matchers.rpc
import com.natpryce.hamkrest.Matcher import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.has 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.willThrow
import net.corda.core.flows.matchers.willReturn
import net.corda.core.messaging.FlowHandle import net.corda.core.messaging.FlowHandle
/** /**
@ -16,14 +14,14 @@ fun <T> willReturn() = has(FlowHandle<T>::returnValue, willReturn())
/** /**
* Matches a flow handle that succeeds with a result matched by the given matcher * Matches a flow handle that succeeds with a result matched by the given matcher
*/ */
fun <T> willReturn(successMatcher: Matcher<T>) = has(FlowHandle<out T>::returnValue, willSucceedWithResult(successMatcher)) fun <T> willReturn(successMatcher: Matcher<T>) = has(FlowHandle<out T>::returnValue, willReturn(successMatcher))
/** /**
* Matches a flow handle that fails, with an exception matched by the given matcher. * Matches a flow handle that fails, with an exception matched by the given matcher.
*/ */
inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has( inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has(
FlowHandle<*>::returnValue, FlowHandle<*>::returnValue,
willFailWithException(failureMatcher)) willThrow(failureMatcher))
/** /**
* Matches a flow handle that fails, with an exception of the specified type. * Matches a flow handle that fails, with an exception of the specified type.