我正在為下面的 java 代碼編寫(xiě) Junit 代碼覆蓋率,而代碼沒(méi)有覆蓋Otherthan Runtime Exception.請(qǐng)找到我下面的java代碼。public class NotifySupervisorJobTask implements Tasklet {private static final Logger LOGGER = LoggerFactory.getLogger(NotifySupervisorJobTask.class); @Autowired private CoreClient client; @Autowired private ItemProcessFailedNotifier itemProcessFailedNotifier; @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { try { client.notifySupervisor(null); LOGGER.info("notifySupervisorJobTask - execute() called"); } catch (RuntimeException exception) { String errorMessage = format("Error in triggering notify supervisor job. Task will be repeated at next scheduled time. Error is: [%s]", exception.getMessage()); LOGGER.error(errorMessage, exception); contribution.setExitStatus(FAILED); itemProcessFailedNotifier.notifyByEmailOnException(chunkContext.getStepContext(), new Exception(errorMessage, exception)); } return RepeatStatus.FINISHED; }}請(qǐng)找到我的案例testcase代碼。other than runtime exception@InjectMocks 私有 NotifySupervisorJobTask notifySupervisorJobTask;@Mockprivate ItemProcessFailedNotifier itemProcessFailedNotifier;@Mockprivate CoreClient client;private ChunkContext chunkContext;private StepContext stepContext;@Beforepublic void setUp() { chunkContext = mock(ChunkContext.class); stepContext = mock(StepContext.class); when(chunkContext.getStepContext()).thenReturn(stepContext);}@Test(expected = Exception.class) public void shouldThrowExceptionOtherThanRuntimeException() throws Exception { Exception ex = mock(Exception.class); doThrow(ex).when(client).notifySupervisor(null); // Line not covered notifySupervisorJobTask.execute(null, chunkContext); // Line not covered verify(itemProcessFailedNotifier).notifyByEmailOnException(stepContext, ex); // Line not covered }
RunTimeException 以外的代碼覆蓋率未覆蓋
料青山看我應(yīng)如是
2022-07-14 17:10:56