forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request corda#3615 from corda/df-reuse-mock-network-example
Reuse mock network, randomising party names to avoid clash
- Loading branch information
Showing
3 changed files
with
164 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/test/kotlin/net/corda/core/matchers/FlowMatchers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.corda.core.matchers | ||
|
||
import com.natpryce.hamkrest.MatchResult | ||
import com.natpryce.hamkrest.Matcher | ||
import net.corda.core.internal.FlowStateMachine | ||
import net.corda.core.utilities.getOrThrow | ||
|
||
/** | ||
* Matches a Flow that succeeds with a result matched by the given matcher | ||
*/ | ||
fun <T> succeedsWith(successMatcher: Matcher<T>) = object : Matcher<FlowStateMachine<T>> { | ||
override val description: String | ||
get() = "A flow that succeeds with ${successMatcher.description}" | ||
|
||
override fun invoke(actual: FlowStateMachine<T>): MatchResult = try { | ||
successMatcher(actual.resultFuture.getOrThrow()) | ||
} catch (e: Exception) { | ||
MatchResult.Mismatch("Failed with $e") | ||
} | ||
} | ||
|
||
/** | ||
* Matches a Flow that fails, with an exception matched by the given matcher. | ||
*/ | ||
inline fun <reified E: Exception> failsWith(failureMatcher: Matcher<E>) = object : Matcher<FlowStateMachine<*>> { | ||
override val description: String | ||
get() = "A flow that fails with a ${E::class.java} that ${failureMatcher.description}" | ||
|
||
override fun invoke(actual: FlowStateMachine<*>): MatchResult = try { | ||
actual.resultFuture.getOrThrow() | ||
MatchResult.Mismatch("Succeeded") | ||
} catch (e: Exception) { | ||
when(e) { | ||
is E -> failureMatcher(e) | ||
else -> MatchResult.Mismatch("Failure class was ${e.javaClass}") | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Matches a Flow that fails, with an exception of the specified type. | ||
*/ | ||
inline fun <reified E: Exception> failsWith() = object : Matcher<FlowStateMachine<*>> { | ||
override val description: String | ||
get() = "A flow that fails with a ${E::class.java}" | ||
|
||
override fun invoke(actual: FlowStateMachine<*>): MatchResult = try { | ||
actual.resultFuture.getOrThrow() | ||
MatchResult.Mismatch("Succeeded") | ||
} catch (e: Exception) { | ||
when(e) { | ||
is E -> MatchResult.Match | ||
else -> MatchResult.Mismatch("Failure class was ${e.javaClass}") | ||
} | ||
} | ||
} |