第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

RunTimeException 以外的代碼覆蓋率未覆蓋

RunTimeException 以外的代碼覆蓋率未覆蓋

我正在為下面的 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 }
查看完整描述

1 回答

?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

您不能告訴 Mockito 拋出模擬方法不可能拋出的異常。

在 Java 中,您有已檢查和未檢查的異常。在您的情況下,未選中的是RuntimeException. 檢查所有其他(包括Exception類(lèi)本身),但它們必須被捕獲或在周?chē)姆椒ê灻新暶鳌?/p>

由于您的notifySupervisor方法顯然沒(méi)有聲明任何已檢查的異常(否則您的execute方法將無(wú)法編譯),Mockito 不能違背編譯器并從其模擬中拋出這樣的異常。


查看完整回答
反對(duì) 回復(fù) 2022-07-14
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)