google / gwtmockito

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

ClassCastException When Calling MenuItem.setTitle #91

Closed spitofland closed 3 years ago

spitofland commented 3 years ago

I setup a mock for the MenuItem.setTitle method, but the mock isn't working. It was working before we updated our SmartClient version.

GwtMockito version: 1.1.9

SmartClient version: 12.1-p20200821 (com.isomorphic.smartgwt.lgpl) Previous SmartClient version: 6.1-p20171202 (Tests were working with this version)

This error occurs when a call is made to the setTitle method on the mock object.

java.lang.ClassCastException: class java.lang.String cannot be cast to class com.smartgwt.client.widgets.menu.MenuItem (java.lang.String is in module java.base of loader 'bootstrap'; com.smartgwt.client.widgets.menu.MenuItem is in unnamed module of loader com.google.gwtmockito.GwtMockitoTestRunner$GwtMockitoClassLoader @6b73368a)
        at com.smartgwt.client.widgets.menu.MenuItem$MockitoMock$686859786.setTitle(Unknown Source)
ekuefler commented 3 years ago

It looks like the latest version of SmartGWT changed setTitle to return a MenuItem instead of void. Have you adjusted your mock to return itself from calls to setTitle?

spitofland commented 3 years ago

That was the problem. Thank you.