I have the below code
public void testInitializeButtons() {
model.initializeButtons();
verify(controller, times(1)).sendMessage(
eq(new Message(eq(Model.OutgoingMessageTypes.BUTTON_STATUSES_CHANGED),
eq(new ButtonStatus(anyBoolean(), eq(false), eq(false), eq(false), eq(false))),
anyObject())));
}
which throws the following exception
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 9 recorded.
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
at se.cambiosys.client.medicalrecords.model.MedicalRecordPanelModelTest.testInitializeButtons(MedicalRecordPanelModelTest.java:88)
Can someone point to me how to write the test correctly?
You can't do that: eq() can be used only for the mocked method parameters, not inside other objects (like you did in the constructor of Message
).
I see three options:
ArgumentCaptor
, and test the properties of the Message with asserts()equals()
in the Message class in order to test equality with another Message, based upon the fields you actually want to verify.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With