I want to mock the situation when missing message.properties.
public class ClassToTest{
private static ResourceBundle bundle = ResourceBundle.getBundle("message");
public static String getMessage(String key){
return bundle.getString(key);
}
}
But when I tried :
@RunWith(PowerMockRunner.class)
@PrepareForTest(ResourceBundle.class)
public class ClassToTestTest{
@Test
public void myTest(){
PowerMockito.spy(ResourceBundle.class);
PowerMockito.when(ResourceBundle.class, "getBundle").thenThrow(new Exception("missing message.properties"));
}
}
I've also tried other ways, but I always get NoClassDefFoundError:org/mockito/exceptions/Reporter