4444
4545import static org .assertj .core .api .Assertions .assertThat ;
4646import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
47+ import static org .assertj .core .api .Assertions .assertThatNoException ;
4748
4849/**
4950 * Tests for {@link ImportTestcontainers}.
5354@ DisabledIfDockerUnavailable
5455class ImportTestcontainersTests {
5556
57+ private final TestGenerationContext generationContext = new TestGenerationContext ();
58+
5659 private AnnotationConfigApplicationContext applicationContext ;
5760
5861 @ AfterEach
@@ -144,13 +147,19 @@ void aotContributionRegistersTestcontainers() {
144147 });
145148 }
146149
150+ @ Test
151+ void importTestcontainersWithDynamicPropertySourceDoNotCauseAotProcessingToFail () {
152+ this .applicationContext = new AnnotationConfigApplicationContext ();
153+ this .applicationContext .register (ContainerDefinitionsWithDynamicPropertySource .class );
154+ new TestcontainersLifecycleApplicationContextInitializer ().initialize (this .applicationContext );
155+ assertThatNoException ().isThrownBy (() -> new ApplicationContextAotGenerator ()
156+ .processAheadOfTime (this .applicationContext , this .generationContext ));
157+ }
158+
147159 @ SuppressWarnings ("unchecked" )
148160 private void compile (BiConsumer <GenericApplicationContext , Compiled > result ) {
149- TestGenerationContext generationContext = new TestGenerationContext ();
150- ClassName className = new ApplicationContextAotGenerator ().processAheadOfTime (this .applicationContext ,
151- generationContext );
152- generationContext .writeGeneratedContent ();
153- TestCompiler .forSystem ().with (generationContext ).compile ((compiled ) -> {
161+ ClassName className = processAheadOfTime ();
162+ TestCompiler .forSystem ().with (this .generationContext ).compile ((compiled ) -> {
154163 GenericApplicationContext freshApplicationContext = new GenericApplicationContext ();
155164 ApplicationContextInitializer <GenericApplicationContext > initializer = compiled
156165 .getInstance (ApplicationContextInitializer .class , className .toString ());
@@ -160,6 +169,13 @@ private void compile(BiConsumer<GenericApplicationContext, Compiled> result) {
160169 });
161170 }
162171
172+ private ClassName processAheadOfTime () {
173+ ClassName className = new ApplicationContextAotGenerator ().processAheadOfTime (this .applicationContext ,
174+ this .generationContext );
175+ this .generationContext .writeGeneratedContent ();
176+ return className ;
177+ }
178+
163179 @ ImportTestcontainers
164180 static class ImportWithoutValue {
165181
0 commit comments