fakir
fakir copied to clipboard
Support indexed getters (gettters with single argument)
I'd like to easily fake an indexed getter. E.g. the method HttpServletRequest::getHeader(String) -> String.
I was thinking it could be done with a map in the faker delegate. Something like:
new Faker<HttpServletRequest>() {
Map<String,String> header = ImmutableMap.of("Host", "www.example.com", ... );
}.get();
Is the special case much more convenient than just providing an implementation?
Map<String, String> headers = ImmutableMap.of("Host", "www.example.com", ... );
new Faker<HttpServletRequest>() {
String getHeader(String header) { return headers.get(header); }
}.get();
Once is no problem. After repeating the same pattern of code for indexed properties of different types in several tests, I thought it would be worth supporting directly in the library.
Also, if the type had indexed getters and setters, Fakir could store key/value pairs passed to the setter into the backing map.
Implementation in pull request #3