在Java单元测试中,此方法的检查异常无效

时间:2020-02-06 14:12:58

标签: java junit powermockito

我正在尝试让我的模拟对象之一在调用特定方法时抛出已检查的异常。我低于例外情况,有人可以帮忙吗

MSThread

              try {
                    if (command.equals("NEAT_TEST"))
                        url = nsReqUrl;
                    else if (command.equals("RETEST_FIBER"))
                        url = retestfiberUrl;
                    else
                        url = nsDirectTl1Url;
                    resultMsg = MSNeatServiceHandler.sendRequest(msg, url);
                } catch (Exception e) {
                    s = e.toString();
                    if (exceptionCnt++ < _nsCmdMaxRetries) {
                        _logger.warn("Neat or Direct TL1 Service exception (attempt " + exceptionCnt + " of "
                                + (_nsCmdMaxRetries + 1) + ").. " + e);
                        resultMsg = MSNeatServiceHandler.sendRequest(msg, url);
                    } else {
                        throw e;
                    }
                }

测试类

@Test
    public void testMSThread_NeatTest3() throws Exception {
        String url = "";
        PowerMockito.doThrow(new RuntimeException()).when(MSNeatServiceHandler.sendRequest(msg,url));
        MSThread result = new MSThread(name, rh, buff, props);
        result.process(msg);
    }

错误

org.mockito.exceptions.base.MockitoException: 
Checked exception is invalid for this method!
Invalid: java.lang.Exception
    at com.verizon.dtix.microsvcagent.MSThreadTest.testMSThread_NeatTest3(MSThreadTest.java:201)

0 个答案:

没有答案