From d103bbc03458a9f5d7d53da3982dd5bd0ea1feac Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 13 Sep 2022 17:41:06 +0100 Subject: [PATCH] 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. --- ...ringBootDependencyInjectionTestExecutionListenerTests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java index 93150cb23dd..a4fde2aaa88 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java @@ -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);