I am facing issue while expecting a setAttribute call from a mock.
MyClass {
public final void setAttribute(String name, Object value) {
// Do Something
}
myClass.setAttribute("Key", "Value");
While invoking the setAttribute operation, String is passed as a value. I have a mock of the above class by the name mockMyClass and in my Expectations block I have the below code.
oneOf(mockMyClass).setAttribute(with(equal("Key")), with(equal("Value")));
I have also tried using any, just to see if the generic works, but that is also giving the same issue.
Exception I am getting:
java.lang.IllegalArgumentException: not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values
Initially I was trying without any matchers and was getting the exception:
oneOf(mockMyClass).setAttribute("Key", "Value");
org.jmock.api.ExpectationError: unexpected invocation
How to get this working? I intend to check for actual values.
make method not final
and use
or with matcher any();
from jmock -- ClassImposteriser cannot create mocks of final classes or mock final methods.