I have a method like this:
public void getSomething(){
...
}
I want to throw an Exception
inside getSomething()
. The
I don't know what you were trying to do. You could just throw an unchecked exception inside your method and then test using JUnit like in my example below.
public void getSomething() {
throw new RuntimeException();
}
JUnit 4 test example:
@Test
public void testGetSomething() {
try {
getSomething();
fail("Expecting RuntimeException!");
} catch (Exception e) {
Logger.getLogger("test").info("Exception was caught: " + e.getClass());
}
}