Ho to mock GXT widgets?
GWT provides GWTMockUtilities which will disarm/restore calls to GWT.create so GWT can be tested using standard mocking frameworks such as EasyMock. How can I do the same for GXT widgets?
The problem seems to be the GXT class has static members which call GWT.getModuleBaseURL(), and that method is not disarmed like create is. Is there a way around this? I've tried modifing GWTBridge to contain this method but it seems the original one is always loaded before mine.
I will open a ticket to remove the static initializer in GXT, as it is not really required. Thanks for bringing it up.
Interesting class there David, thanks for pointing it out.
I've made the necessary modifications to the GXT class, and I've added a few simple unit tests using Mockito to GXT to ensure that a decent sampling of classes are able to be mocked.
The one main gotcha I found in that testing was the ToolButton, since all of those static images require GWT.create to not return null, else they will cause a NPE. I've build a mock class for when GWT.create is unwired, and it appears to pass these same tests. I've looked for all other invocations of GWT.create to ensure that we aren't using it for any static fields that could cause a NPE in class initialization, but haven't found any.
This changeset is in SVN and the latest nightly builds, and will be available in the next release.