2424import org .junit .jupiter .api .BeforeEach ;
2525import org .junit .jupiter .api .Disabled ;
2626import org .junit .jupiter .api .Test ;
27+ import org .junit .jupiter .params .ParameterizedTest ;
28+ import org .junit .jupiter .params .provider .ValueSource ;
2729
2830import org .springframework .aot .hint .RuntimeHints ;
2931import org .springframework .aot .hint .predicate .RuntimeHintsPredicates ;
@@ -199,10 +201,13 @@ void whenUseMainMethodWhenAvailableAndNoMainMethod() {
199201 assertThat (applicationContext .getEnvironment ().getActiveProfiles ()).isEmpty ();
200202 }
201203
202- @ Test
203- void whenUseMainMethodWhenAvailableAndMainMethod () {
204- TestContext testContext = new ExposedTestContextManager (UseMainMethodWhenAvailableAndMainMethod .class )
205- .getExposedTestContext ();
204+ @ ParameterizedTest
205+ @ ValueSource (classes = { UsePublicMainMethodWhenAvailableAndMainMethod .class ,
206+ UsePublicParameterlessMainMethodWhenAvailableAndMainMethod .class ,
207+ UsePackagePrivateMainMethodWhenAvailableAndMainMethod .class ,
208+ UsePackagePrivateParameterlessMainMethodWhenAvailableAndMainMethod .class })
209+ void whenUseMainMethodWhenAvailableAndMainMethod (Class <?> testClass ) {
210+ TestContext testContext = new ExposedTestContextManager (testClass ).getExposedTestContext ();
206211 ApplicationContext applicationContext = testContext .getApplicationContext ();
207212 assertThat (applicationContext .getEnvironment ().getActiveProfiles ()).contains ("frommain" );
208213 }
@@ -264,11 +269,11 @@ void whenMainMethodNotAvailableReturnsNoAotContribution() throws Exception {
264269 void whenMainMethodPresentRegisterReflectionHints () throws Exception {
265270 SpringBootContextLoader contextLoader = new SpringBootContextLoader ();
266271 MergedContextConfiguration contextConfiguration = BootstrapUtils
267- .resolveTestContextBootstrapper (UseMainMethodWhenAvailableAndMainMethod .class )
272+ .resolveTestContextBootstrapper (UsePublicMainMethodWhenAvailableAndMainMethod .class )
268273 .buildMergedContextConfiguration ();
269274 RuntimeHints runtimeHints = new RuntimeHints ();
270275 contextLoader .loadContextForAotProcessing (contextConfiguration , runtimeHints );
271- assertThat (RuntimeHintsPredicates .reflection ().onMethod (ConfigWithMain .class , "main" ).invoke ())
276+ assertThat (RuntimeHintsPredicates .reflection ().onMethod (ConfigWithPublicMain .class , "main" ).invoke ())
272277 .accepts (runtimeHints );
273278 }
274279
@@ -370,12 +375,28 @@ static class UseMainMethodWhenAvailableAndNoMainMethod {
370375
371376 }
372377
373- @ SpringBootTest (classes = ConfigWithMain .class , useMainMethod = UseMainMethod .WHEN_AVAILABLE )
374- static class UseMainMethodWhenAvailableAndMainMethod {
378+ @ SpringBootTest (classes = ConfigWithPublicMain .class , useMainMethod = UseMainMethod .WHEN_AVAILABLE )
379+ static class UsePublicMainMethodWhenAvailableAndMainMethod {
380+
381+ }
382+
383+ @ SpringBootTest (classes = ConfigWithPublicParameterlessMain .class , useMainMethod = UseMainMethod .WHEN_AVAILABLE )
384+ static class UsePublicParameterlessMainMethodWhenAvailableAndMainMethod {
375385
376386 }
377387
378- @ SpringBootTest (classes = ConfigWithMain .class , useMainMethod = UseMainMethod .NEVER )
388+ @ SpringBootTest (classes = ConfigWithPackagePrivateMain .class , useMainMethod = UseMainMethod .WHEN_AVAILABLE )
389+ static class UsePackagePrivateMainMethodWhenAvailableAndMainMethod {
390+
391+ }
392+
393+ @ SpringBootTest (classes = ConfigWithPackagePrivateParameterlessMain .class ,
394+ useMainMethod = UseMainMethod .WHEN_AVAILABLE )
395+ static class UsePackagePrivateParameterlessMainMethodWhenAvailableAndMainMethod {
396+
397+ }
398+
399+ @ SpringBootTest (classes = ConfigWithPublicMain .class , useMainMethod = UseMainMethod .NEVER )
379400 static class UseMainMethodNever {
380401
381402 }
@@ -391,7 +412,7 @@ static class NoMainMethodWithBeanThrowingException {
391412 }
392413
393414 @ SpringBootTest (useMainMethod = UseMainMethod .ALWAYS )
394- @ ContextHierarchy ({ @ ContextConfiguration (classes = ConfigWithMain .class ),
415+ @ ContextHierarchy ({ @ ContextConfiguration (classes = ConfigWithPublicMain .class ),
395416 @ ContextConfiguration (classes = AnotherConfigWithMain .class ) })
396417 static class UseMainMethodWithContextHierarchy {
397418
@@ -422,10 +443,37 @@ static class Config {
422443 }
423444
424445 @ SpringBootConfiguration (proxyBeanMethods = false )
425- public static class ConfigWithMain {
446+ public static class ConfigWithPublicMain {
426447
427448 public static void main (String [] args ) {
428- new SpringApplication (ConfigWithMain .class ).run ("--spring.profiles.active=frommain" );
449+ new SpringApplication (ConfigWithPublicMain .class ).run ("--spring.profiles.active=frommain" );
450+ }
451+
452+ }
453+
454+ @ SpringBootConfiguration (proxyBeanMethods = false )
455+ public static class ConfigWithPublicParameterlessMain {
456+
457+ public static void main () {
458+ new SpringApplication (ConfigWithPublicMain .class ).run ("--spring.profiles.active=frommain" );
459+ }
460+
461+ }
462+
463+ @ SpringBootConfiguration (proxyBeanMethods = false )
464+ public static class ConfigWithPackagePrivateMain {
465+
466+ static void main (String [] args ) {
467+ new SpringApplication (ConfigWithPublicMain .class ).run ("--spring.profiles.active=frommain" );
468+ }
469+
470+ }
471+
472+ @ SpringBootConfiguration (proxyBeanMethods = false )
473+ public static class ConfigWithPackagePrivateParameterlessMain {
474+
475+ static void main () {
476+ new SpringApplication (ConfigWithPublicMain .class ).run ("--spring.profiles.active=frommain" );
429477 }
430478
431479 }
0 commit comments