My code:
public String getTemplate(TestType fileType) {
Util util = new Util();
try {
return util.addPrefix(util.getTemplate(fileType));
} catch (IOException e) {
logger.warn(e.getMessage());
throw new MyException(...);
} catch (SyntaxException e) {
logger.warn(e.getMessage());
throw new MyException(...);
}
}
Test class:
TestType testType = TestType.main;
Util util = spy(new Util()); //or Util util = mock(Util.class);
when(util.getTemplate(testType)).thenThrow(new SyntaxException(...)); //or IOException
String out = runService.getTemplate(testType);
But it doesn't work. Since this method creates a new class. Is it possible to mock the creation of a new inner class without using PowerMock?