mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Eliminate needless equalTo
This commit is contained in:
parent
c0966067cc
commit
f3d9750ea5
@ -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) {
|
||||
|
@ -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 <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
|
||||
*/
|
||||
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 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.
|
||||
*/
|
||||
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
|
||||
get() = "is a future that will fail with a ${E::class.java.simpleName} that ${failureMatcher.description}"
|
||||
|
||||
|
@ -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 <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
|
||||
*/
|
||||
fun <T> willReturn(successMatcher: Matcher<T>) = has(
|
||||
FlowStateMachine<out T>::resultFuture,
|
||||
willSucceedWithResult(successMatcher))
|
||||
willReturn(successMatcher))
|
||||
|
||||
/**
|
||||
* Matches a Flow that fails, with an exception matched by the given matcher.
|
||||
*/
|
||||
inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has(
|
||||
FlowStateMachine<*>::resultFuture,
|
||||
willFailWithException(failureMatcher))
|
||||
willThrow(failureMatcher))
|
||||
|
||||
/**
|
||||
* Matches a Flow that fails, with an exception of the specified type.
|
||||
|
@ -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 <T> willReturn() = has(FlowHandle<T>::returnValue, willReturn())
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
inline fun <reified E: Exception> willThrow(failureMatcher: Matcher<E>) = has(
|
||||
FlowHandle<*>::returnValue,
|
||||
willFailWithException(failureMatcher))
|
||||
willThrow(failureMatcher))
|
||||
|
||||
/**
|
||||
* Matches a flow handle that fails, with an exception of the specified type.
|
||||
|
Loading…
x
Reference in New Issue
Block a user