The DesktopForm of the minifig application has a method updateSummary():
protected void updateSummary() {
getSummaryField().setValue(PartUtility.calculateSummary(
getNameField().getValue(),
getHeadField().getValue(),
getTorsoField().getValue(),
getLegsField().getValue()
));
}
When I try to run a test like this (extended version of testSetName()):
@Test
public void testSetName() throws Exception {
DesktopForm form = Mockito.spy(createFormWithState(true, true, true));
form.startView(); //<--this calls updateSummary() in ViewHandler.execLoad() [using reloadForm()]
form.getNameField().setValue("Bob"); //<-- this calls updateSummary() in NameField.execChangedValue()
Assert.assertTrue(form.getSummaryField().getValue().startsWith("Bob"));
Mockito.verify(form, Mockito.times(1)).updateImage();
Mockito.verify(form, Mockito.times(2)).updateSummary();
}
This test is failing:
org.mockito.exceptions.verification.TooLittleActualInvocations:
desktopForm.updateSummary();
Wanted 2 times:
-> at org.eclipsescout.demo.minifigcreator.client.ui.forms.DesktopFormTest.testSetName(DesktopFormTest.java:146)
But was 1 time:
-> at org.eclipsescout.demo.minifigcreator.client.ui.forms.DesktopFormTest.testSetName(DesktopFormTest.java:140)
When I put a break point in PartUtility.calculateSummary(..) I see the 2 calls:
First call:
Second call:
In the second call, the DesktopForm is not instrumented by Mockito. This is why the spy do not think that updateSummary() was called twice.
Does Mockito have a problem with the scout inner-classes?
.