public void onActivate( com.gwtext.client.widgets.Panel panel )
if ( !( panel instanceof MyCustomGwtExtPanel ) )
throw new IllegalArgumentException( "Panel must be a MyCustomGwtPanel." );
… snip …
I had one test to test that an exception is thrown:
@Test(expectedExceptions = IllegalArgumentException.class)
public void testOnActivate_unexpectedPanel()
Panel panel = new Panel();
new TripReportsPanelListener().onActivate( panel );
It was so simple, I guess it just had to fail:
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
… 23 more
By using GWTMockUtilities.disarm in the setup and GWTMockUtilities.restore in the teardown, I made some progress by ended up with this error instead:
at com.gwtext.client.widgets.Component.checkExtVer(Native Method)
The solution is right there in the stacktrace from Google.
I extended GWTTestCase but continued to get the same errors. The reason is simple enough, but has bitten me a a couple of times before. GWTTestCase is written using the old JUnit 3 style tests. My tests were using TestNG annotations which tells TestNG to run the tests as TestNG tests. Consequently the setup and teardown methods in GWTTestCase never get called. JUnit acts the same way if you mix and match JUnit 3 and 4 style test declarations.
It’s been a frustrating experience with UnsatisfiedLinkErrors and NoClassDefFoundErrors, but I eventually got what should be a simple unit test working. And it sucks that my seemingly innocent unit test have so many dependencies. It also stinks that GWT must be started up to run the tests resulting in a feedback loop increase of 10-15 seconds.