|
|
@ -18,6 +18,7 @@ package org.springframework.boot.test.autoconfigure;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.WebApplicationType;
|
|
|
|
import org.springframework.boot.WebApplicationType;
|
|
|
@ -31,6 +32,7 @@ import org.springframework.test.context.TestContext;
|
|
|
|
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
|
|
|
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
@ -45,6 +47,9 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
|
|
|
|
@Rule
|
|
|
|
@Rule
|
|
|
|
public OutputCapture out = new OutputCapture();
|
|
|
|
public OutputCapture out = new OutputCapture();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
|
|
private SpringBootDependencyInjectionTestExecutionListener reportListener = new SpringBootDependencyInjectionTestExecutionListener();
|
|
|
|
private SpringBootDependencyInjectionTestExecutionListener reportListener = new SpringBootDependencyInjectionTestExecutionListener();
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -74,6 +79,18 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
|
|
|
|
this.out.expect(containsString("Negative matches"));
|
|
|
|
this.out.expect(containsString("Negative matches"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void originalFailureIsThrownWhenReportGenerationFails() throws Exception {
|
|
|
|
|
|
|
|
TestContext testContext = mock(TestContext.class);
|
|
|
|
|
|
|
|
IllegalStateException originalFailure = new IllegalStateException();
|
|
|
|
|
|
|
|
given(testContext.getTestInstance()).willThrow(originalFailure);
|
|
|
|
|
|
|
|
SpringApplication application = new SpringApplication(Config.class);
|
|
|
|
|
|
|
|
application.setWebEnvironment(false);
|
|
|
|
|
|
|
|
given(testContext.getApplicationContext()).willThrow(new RuntimeException());
|
|
|
|
|
|
|
|
this.thrown.expect(is(originalFailure));
|
|
|
|
|
|
|
|
this.reportListener.prepareTestInstance(testContext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ImportAutoConfiguration(JacksonAutoConfiguration.class)
|
|
|
|
@ImportAutoConfiguration(JacksonAutoConfiguration.class)
|
|
|
|
static class Config {
|
|
|
|
static class Config {
|
|
|
|