Browse Source

Polish "Add Bootstrapper initialize method to fix typo"

See gh-25400
pull/25523/head
Andy Wilkinson 5 years ago
parent
commit
f9ef05f71e
  1. 54
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

54
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

@ -1247,6 +1247,29 @@ class SpringApplicationTests { @@ -1247,6 +1247,29 @@ class SpringApplicationTests {
assertThat(applicationContext.getBean("test")).isEqualTo("boot");
}
@Test
void whenABootstrapperImplementsOnlyTheOldMethodThenItIsCalled() {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
OnlyOldMethodTestBootstrapper bootstrapper = new OnlyOldMethodTestBootstrapper();
application.addBootstrapper(bootstrapper);
try (ConfigurableApplicationContext applicationContext = application.run()) {
assertThat(bootstrapper.intitialized).isTrue();
}
}
@Test
void whenABootstrapperImplementsTheOldMethodAndTheNewMethodThenOnlyTheNewMethodIsCalled() {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
BothMethodsTestBootstrapper bootstrapper = new BothMethodsTestBootstrapper();
application.addBootstrapper(bootstrapper);
try (ConfigurableApplicationContext applicationContext = application.run()) {
assertThat(bootstrapper.intitialized).isFalse();
assertThat(bootstrapper.initialized).isTrue();
}
}
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(
S state) {
return (argument) -> (argument instanceof AvailabilityChangeEvent<?>)
@ -1720,4 +1743,35 @@ class SpringApplicationTests { @@ -1720,4 +1743,35 @@ class SpringApplicationTests {
}
static class OnlyOldMethodTestBootstrapper implements Bootstrapper {
private boolean intitialized;
@Override
@SuppressWarnings("deprecation")
public void intitialize(BootstrapRegistry registry) {
this.intitialized = true;
}
}
static class BothMethodsTestBootstrapper implements Bootstrapper {
private boolean intitialized;
private boolean initialized;
@Override
@SuppressWarnings("deprecation")
public void intitialize(BootstrapRegistry registry) {
this.intitialized = true;
}
@Override
public void initialize(BootstrapRegistry registry) {
this.initialized = true;
}
}
}

Loading…
Cancel
Save