I want to create a JUnit test for this private method:
@Component
public class ReportingProcessor {
@EventListener
private void collectEnvironmentData(ContextRefreshedEvent event) {
}
}
I tried this:
@ContextConfiguration
@SpringBootTest
public class ReportingTest {
@Autowired
ReportingProcessor reportingProcessor;
@Test
public void reportingTest() throws Exception {
ContextRefreshedEvent contextRefreshedEvent = PowerMockito.mock(ContextRefreshedEvent.class);
Whitebox.invokeMethod(reportingProcessor, "collectEnvironmentData", contextRefreshedEvent);
}
}
When I run the code I get:
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
Do you know ho I can fix this issue?