Skip to content

Commit

Permalink
Polish "Back off if a custom ApplicationAvailability bean is present"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Apr 19, 2023
1 parent 5e95ba8 commit 1b832d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class ApplicationAvailabilityAutoConfiguration {

@Bean
@ConditionalOnMissingBean(ApplicationAvailability.class)
@ConditionalOnMissingBean
public ApplicationAvailability applicationAvailability() {
return new ApplicationAvailabilityBean();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.availability.ApplicationAvailability;
import org.springframework.boot.availability.AvailabilityChangeEvent;
import org.springframework.boot.availability.AvailabilityState;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

/**
* Tests for {@link ApplicationAvailabilityAutoConfiguration}
Expand All @@ -46,35 +43,12 @@ void providerIsPresentWhenNotRegistered() {
}

@Test
void providerIsPresentWithRegisteredOne() {
this.contextRunner.withUserConfiguration(ApplicationAvailabilityConfig.class)
void providerIsNotConfiguredWhenCustomOneIsPresent() {
this.contextRunner
.withBean("customApplicationAvailability", ApplicationAvailability.class,
() -> mock(ApplicationAvailability.class))
.run(((context) -> assertThat(context).hasSingleBean(ApplicationAvailability.class)
.hasBean("customApplicationAvailability")));
}

@Configuration(proxyBeanMethods = false)
static class ApplicationAvailabilityConfig {

@Bean
ApplicationAvailability customApplicationAvailability() {
return new ApplicationAvailability() {
@Override
public <S extends AvailabilityState> S getState(Class<S> stateType, S defaultState) {
return null;
}

@Override
public <S extends AvailabilityState> S getState(Class<S> stateType) {
return null;
}

@Override
public <S extends AvailabilityState> AvailabilityChangeEvent<S> getLastChangeEvent(Class<S> stateType) {
return null;
}
};
}

}

}

0 comments on commit 1b832d8

Please sign in to comment.