I've got a class that looks like this:
public class Foo {
public meth() {
try {
privMethod();
System.out.println("Yay!");
} catch (FooException e) {
System.out.println("Boo!");
}
}
private void privMethod() throws FooException {
//doOtherStuff
if (someCondition()) {
throw new FooException();
}
}
private class FooException extends Exception {
FooException(String message) { super(message); }
}
}
I want to write a unit test for this, using Mockito and Powermock. I know I can mock the private method like this:
Foo spy = PowerMockito.spy(new Foo())
PowerMockito.doNothing().when(spy, "privMethod");
But how do I tell it to throw the exception? I know it'll be something like this:
Powermockito.doThrow(/*what goes here?*/).when(spy, "privMethod");
What goes there?
Note that the exception is a private inner class, so I can't just do doThrow(new FooException())
, since FooException
isn't accessible from the unit test.