Skip to content

Commit 3a92351

Browse files
committed
GH-185 - Allow verification of events after method invocation stimulus.
1 parent b834c25 commit 3a92351

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spring-modulith-test/src/main/java/org/springframework/modulith/test/Scenario.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,18 @@ public void andVerify(BiConsumer<S, T> consumer) {
433433

434434
consumer.accept(result.first(), result.second());
435435
}
436+
437+
/**
438+
* Verifies the underlying {@link AssertablePublishedEvents}.
439+
*
440+
* @param events must not be {@literal null}.
441+
*/
442+
public void andVerifyEvents(Consumer<AssertablePublishedEvents> events) {
443+
444+
Assert.notNull(events, "Consumer must not be null!");
445+
446+
events.accept(Scenario.this.events);
447+
}
436448
}
437449

438450
public class EventResult<E> {

spring-modulith-test/src/test/java/org/springframework/modulith/test/ScenarioUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ void replacesSpecialCustomizerBehindDefaultOne() {
382382
assertThat(specialCustomizer.invoked).isFalse();
383383
}
384384

385+
@Test // GH-185
386+
@SuppressWarnings("unchecked")
387+
void invokesEventVerificationOnMethodInvocationStimulus() {
388+
389+
Consumer<AssertablePublishedEvents> consumer = mock(Consumer.class);
390+
391+
new Scenario(tx, publisher, new DefaultAssertablePublishedEvents())
392+
.stimulate(() -> {})
393+
.andWaitForStateChange(() -> true)
394+
.andVerifyEvents(consumer);
395+
396+
verify(consumer).accept(any());
397+
}
398+
385399
private Fixture givenAScenario(Consumer<Scenario> consumer) {
386400
return new Fixture(consumer, DELAY, null, new DefaultAssertablePublishedEvents());
387401
}

0 commit comments

Comments
 (0)