Avoid returning null from TestContext.getTestClass()

Our mock didn't configure an expectation so null was returned. That's
prohibited by the javadoc and some recent Framework changes mean that
it's no longer tolerated.
This commit is contained in:
Andy Wilkinson 2022-09-13 17:41:06 +01:00
parent 436657bbec
commit d103bbc034
1 changed files with 4 additions and 0 deletions

View File

@ -53,8 +53,10 @@ class SpringBootDependencyInjectionTestExecutionListenerTests {
}
@Test
@SuppressWarnings("unchecked")
void prepareFailingTestInstanceShouldPrintReport(CapturedOutput output) throws Exception {
TestContext testContext = mock(TestContext.class);
given(testContext.getTestClass()).willReturn((Class) Config.class);
given(testContext.getTestInstance()).willThrow(new IllegalStateException());
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
@ -71,8 +73,10 @@ class SpringBootDependencyInjectionTestExecutionListenerTests {
}
@Test
@SuppressWarnings("unchecked")
void originalFailureIsThrownWhenReportGenerationFails() {
TestContext testContext = mock(TestContext.class);
given(testContext.getTestClass()).willReturn((Class) Config.class);
IllegalStateException originalFailure = new IllegalStateException();
given(testContext.getTestInstance()).willThrow(originalFailure);
SpringApplication application = new SpringApplication(Config.class);