GH-136 - API polishing for Scenario.

Move the registration of cleanup callbacks to the intermediate When type to avoid overloads of Scenario.stimulate(…). Also, to prevent multiple lambda-style parameters for ….stimulate(…) as they don't distinguish nice on the declaration side. Removed the varargs from ….publish(…) methods and wait for the actual request to add support for preparing, in transaction callbacks (potentially to be introduced as ….prepare(…) method).

The default acceptance criteria for state change expectations now also considers a boolean true as concluding method result.
This commit is contained in:
Oliver Drotbohm
2023-02-23 22:14:20 +01:00
parent 50d8659595
commit bb466f99e9
2 changed files with 69 additions and 96 deletions

View File

@@ -83,7 +83,7 @@ class ScenarioUnitTests {
@Test // GH-136
void matchesEventsWithPredicate() throws Throwable {
Consumer<Scenario> consumer = it -> publishObject(it)
Consumer<Scenario> consumer = it -> it.publish(() -> 41)
.forEventOfType(SomeEvent.class)
.matching(__ -> __.payload().startsWith("foo"))
.toArrive();
@@ -194,7 +194,8 @@ class ScenarioUnitTests {
BiConsumer<String, Integer> verification = mock(BiConsumer.class);
Consumer<Integer> cleanupCallback = mock(Consumer.class);
Consumer<Scenario> consumer = it -> it.stimulate(() -> 41, cleanupCallback)
Consumer<Scenario> consumer = it -> it.stimulate(() -> 41)
.andCleanup(cleanupCallback)
.forEventOfType(String.class)
.toArriveAndVerify(verification);
@@ -211,9 +212,10 @@ class ScenarioUnitTests {
void triggersCleanupOnFailure() {
BiConsumer<String, Integer> verification = mock(BiConsumer.class);
Consumer<Integer> cleanupCallback = mock(Consumer.class);
Runnable cleanupCallback = mock(Runnable.class);
Consumer<Scenario> consumer = it -> it.stimulate((tx) -> 41, cleanupCallback)
Consumer<Scenario> consumer = it -> it.stimulate((tx) -> 41)
.andCleanup(cleanupCallback)
.andWaitAtMost(WAIT_TIME)
.forEventOfType(String.class)
.toArriveAndVerify(verification);
@@ -223,7 +225,7 @@ class ScenarioUnitTests {
.expectFailure();
verify(verification, never()).accept(any(), any());
verify(cleanupCallback).accept(41);
verify(cleanupCallback).run();
}
@Test // GH-136
@@ -266,8 +268,8 @@ class ScenarioUnitTests {
Consumer<String> verification = mock(Consumer.class);
Consumer<Scenario> consumer = it -> it.stimulate(() -> 41)
.andWaitForStateChange(delayed("Foo"))
Consumer<Scenario> consumer = it -> it.stimulate(() -> {})
.forStateChange(delayed("Foo"))
.andVerify(verification);
givenAScenario(consumer)