You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implementation of FakeUiBinderProvider erases the type of all of the fields it injects (e.g. Box<String> gets mocked as Box<Object>). It isn't possible to pass the necessary type information through GWT.create() (since it only takes a class literal), but there may be alternatives I'm missing.
The mock for myWidget.message will be a raw Box, so get() returns a String, causing a ClassCastException:
java.lang.ClassCastException: org.mockito.internal.creation.jmock.ClassImposterizer$ClassWithSuperclassToWorkAroundCglibBug$$EnhancerByMockitoWithCGLIB$$ef767c84 cannot be cast to java.lang.String
at mockitobug.MyWidgetTest.simpleTest(MyWidgetTest.java:44)
...
I encountered this because if you write:
when(myWidget.message.get()).thenReturn("Hello");
Then the eclipse compiler will generate a string cast on the result of myWidget.message.get(), which causes the test to crash. (javac is unaffected, except for specific versions of javac9.)
Running mockitobug.MyWidgetTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.565 sec <<< FAILURE!
simpleTest(mockitobug.MyWidgetTest) Time elapsed: 0.237 sec <<< ERROR!
java.lang.ClassCastException: org.mockito.internal.creation.jmock.ClassImposterizer$ClassWithSuperclassToWorkAroundCglibBug$$EnhancerByMockitoWithCGLIB$$ef7df407 cannot be cast to java.lang.String
at mockitobug.MyWidgetTest.simpleTest(MyWidgetTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
...
The text was updated successfully, but these errors were encountered:
Yeah, the fact that we call GWT.create to populate UiFields will be problematic. We probably don't need to do this though - we could instead provide some sort of back door to invoke the underlying create code directly with additional type information. Would take some experimenting to figure out if we have the necessary information available and how to get it into Mockito.
The implementation of
FakeUiBinderProvider
erases the type of all of the fields it injects (e.g.Box<String>
gets mocked asBox<Object>
). It isn't possible to pass the necessary type information throughGWT.create()
(since it only takes a class literal), but there may be alternatives I'm missing.Here's an example:
The mock for
myWidget.message
will be a rawBox
, soget()
returns aString
, causing aClassCastException
:I encountered this because if you write:
Then the eclipse compiler will generate a string cast on the result of
myWidget.message.get()
, which causes the test to crash. (javac is unaffected, except for specific versions of javac9.)Here's the complete repro:
The text was updated successfully, but these errors were encountered: