GH-1110 - Register AssertablePublishedEvents in ApplicationContext if AssertJ is on the classpath.

We now check for the presence of AssertJ on the classpath and rather register an instance of ApplicationPublishedEvents in the ApplicationContext if present.
This commit is contained in:
Oliver Drotbohm
2025-03-17 19:01:53 +01:00
parent 8df778b039
commit 433a22559e
4 changed files with 72 additions and 9 deletions

View File

@@ -21,9 +21,12 @@ import example.module.SampleTestA;
import example.module.SampleTestB;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.modulith.core.ApplicationModule;
import org.springframework.modulith.core.ApplicationModuleIdentifier;
import org.springframework.modulith.test.ModuleContextCustomizerFactory.ModuleContextCustomizer;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
/**
* Unit tests for {@link ModuleTypeExcludeFilter}.
@@ -65,4 +68,18 @@ class ModuleContextCustomizerUnitTests {
assertThat(right).isEqualTo(left);
assertThat(left).hasSameHashCodeAs(right);
}
@Test // GH-1110
void registersAssertablePublishedEvents() {
var context = new AnnotationConfigApplicationContext();
var loader = new AnnotationConfigContextLoader();
new ModuleContextCustomizer(SampleTestA.class)
.customizeContext(context, new MergedContextConfiguration(SampleTestA.class, null, null, null, loader));
assertThat(context.getApplicationListeners()).hasSize(1)
.element(0)
.isInstanceOf(AssertablePublishedEvents.class);
}
}