I\'m failing to mock ResourceBundle.getString()
.
This is my code:
ResourceBundle schemaBundle = Mockito.mock(ResourceBundle.class);
Mockito.
Instead of mocking you can create a dummy ResourceBundle implementation, and then pass it in .thenReturn(resourceBundle)
:
import java.util.ResourceBundle;
ResourceBundle dummyResourceBundle = new ResourceBundle() {
@Override
protected Object handleGetObject(String key) {
return "fake_translated_value";
}
@Override
public Enumeration getKeys() {
return Collections.emptyEnumeration();
}
};
// Example usage
when(request.getResourceBundle(any(Locale.class))).thenReturn(dummyResourceBundle)
If you need the actual keys and values, then you'll need to provide an implementation for getKeys()
, e.g. a hashmap for storage and key lookup.