I\'m failing to mock ResourceBundle.getString()
.
This is my code:
ResourceBundle schemaBundle = Mockito.mock(ResourceBundle.class);
Mockito.
@Powermockito did not worked as ResourceBundle.class have static final methods which were not easy to mock.
I tried.
In the Main Class extract your method inside another public method, and then overide it with implementaion.
Here ReviewEChannelApplicationMBean is my Controller, where i overrriden the getBundle.
ReviewEChannelApplicationMBean = spy(new ReviewEChannelApplicationMBean(){
@Override
public ResourceBundle getBundle(FacesContext fcContext) {
return TestDataBuilder.getResourceBundle();
}
});
//This Class i my TestDataBuilder using ListResourceBundle
public class TestDataBuilder {
public static ResourceBundle getResourceBundle() {
return new ListResourceBundle(){
@Override
protected Object[][] getContents() {
return contents;
}
private Object[][] contents = {
{"test1","01"},
{"test2","01"},
{"test3","01"},
{"test4","01"}
};
};
}
}