There is a class.
class A {
public String getValue(String key) {
return key;
}
}
Is it possible to write such a test that would test that method getValue()
returns a key as a value.
There is my try:
A aMock = mock(A.class);
when(aMock.getValue("key")).thenReturn("key");
That's nice, but this works only for one particular parameter value. But I, probably, need some kind of rule like "for each parameter it would return the parameter itself whatever value this parameter would have"
More context, what I'm actually trying to test:
Let's say we have a file with key=value
entries, like a resource bundle.
The method would return key if it could not find a value. For example if we search by "user.name", we going to have "Bob" if it is defined. If not - it would return key (user.name) itsef, because I do not want this method returns me null
.
(This is actually a model of org.springframework.context.MessageSource.getMessage
- it behaves similar way)
So.. updated
public String getValue(String key) {
// some code ...might be here, but we care about a result
if (valueWasFound) {
return theValue;
}
return key;
}