I want to execute the catch block of the below code.
public String getResult() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
throw new Exception(e);
}
}
i write the test case as follows,
@Test
public void getResultTest() throws Exception{
doThrow(Exception.class).when(mockInetAddress).getLocalHost();
mockTestClassObj.getResult();
//code for verify exception
}
This executes fine instead throws exception. Can't i throw exception in this scenario?