use of org.mockito.ArgumentMatchers in project spring-boot by spring-projects.
the class SpringApplicationTests method customApplicationStartupPublishStartupStepsWithFailure.
@Test
void customApplicationStartupPublishStartupStepsWithFailure() {
ApplicationStartup applicationStartup = mock(ApplicationStartup.class);
StartupStep startupStep = mock(StartupStep.class);
given(applicationStartup.start(anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), ArgumentMatchers.<Supplier<String>>any())).willReturn(startupStep);
SpringApplication application = new SpringApplication(BrokenPostConstructConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.setApplicationStartup(applicationStartup);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run);
then(applicationStartup).should().start("spring.boot.application.starting");
then(applicationStartup).should().start("spring.boot.application.environment-prepared");
then(applicationStartup).should().start("spring.boot.application.failed");
long startCount = mockingDetails(applicationStartup).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("start(")).count();
long endCount = mockingDetails(startupStep).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("end(")).count();
assertThat(startCount).isEqualTo(endCount);
}
use of org.mockito.ArgumentMatchers in project spring-boot by spring-projects.
the class SpringApplicationTests method customApplicationStartupPublishStartupSteps.
@Test
void customApplicationStartupPublishStartupSteps() {
ApplicationStartup applicationStartup = mock(ApplicationStartup.class);
StartupStep startupStep = mock(StartupStep.class);
given(applicationStartup.start(anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), ArgumentMatchers.<Supplier<String>>any())).willReturn(startupStep);
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.setApplicationStartup(applicationStartup);
this.context = application.run();
assertThat(this.context.getBean(ApplicationStartup.class)).isEqualTo(applicationStartup);
then(applicationStartup).should().start("spring.boot.application.starting");
then(applicationStartup).should().start("spring.boot.application.environment-prepared");
then(applicationStartup).should().start("spring.boot.application.context-prepared");
then(applicationStartup).should().start("spring.boot.application.context-loaded");
then(applicationStartup).should().start("spring.boot.application.started");
then(applicationStartup).should().start("spring.boot.application.ready");
long startCount = mockingDetails(applicationStartup).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("start(")).count();
long endCount = mockingDetails(startupStep).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("end(")).count();
assertThat(startCount).isEqualTo(endCount);
}
Aggregations