Closed Martin-Luft closed 7 years ago
FYI: Still an issue with latest Mockito 2.2.9
Do you mean that calling getValue
after calling setValue
on a TextBox
doesn't return the value that was set? I think this is how things have always worked - were you seeing different behavior on an earlier version of Mockito?
GwtMockito doesn't do any emulation of UI widgets, it just swaps them out for Mockito mocks, which don't know anything about the relationship between getValue
and setValue
. If you want to control what's returned from calls to mocks, you need to set up a stub like when(myTextBox.getValue()).thenReturn("some text");
@ekuefler I use a simple answer object to connect the getter and setter methods. But since Mockito 2.1.0 the answer()
method from the answer object is not called when using setValue(null)
.
The problem ist that the setValue()
method is stubbed as textBox.setValue(<any string>);
but nul
l does not match inside InstanceOf.matches()
...
OK the new Mockito 2 API says:
Since Mockito 2.1.0, only allow non-null String. As this is a nullable reference, the suggested API to match null wrapper would be isNull(). We felt this change would make tests harness much safer that it was with Mockito 1.x.
So I changed ArgumentMatchers.anyString()
to ArgumentMatchers.any()
.
Since Mockito 2.1.0 TextBox.setValue(null) does not work anymore (the last value remains).