google / gwtmockito

Better GWT unit testing
https://google.github.io/gwtmockito
Apache License 2.0
157 stars 50 forks source link

Since Mockito 2.1.0 TextBox.setValue(null) does not work anymore #62

Closed Martin-Luft closed 7 years ago

Martin-Luft commented 7 years ago

Since Mockito 2.1.0 TextBox.setValue(null) does not work anymore (the last value remains).

Martin-Luft commented 7 years ago

FYI: Still an issue with latest Mockito 2.2.9

ekuefler commented 7 years ago

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");

Martin-Luft commented 7 years ago

@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 null does not match inside InstanceOf.matches()...

Martin-Luft commented 7 years ago

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().