PDA

View Full Version : GXT and GWTMockUtilities



mraible
16 Feb 2009, 4:30 PM
I'm trying to refactor some tests from using GWTTestCase to JUnit's TestCase. This seems possible with the help of GWTMockUtilities:

http://code.google.com/p/google-web-toolkit/source/browse/releases/1.5/user/src/com/google/gwt/junit/GWTMockUtilities.java?r=3125

Here's my test:



@Override
public void setUp() {
GWTMockUtilities.disarm();
galleryController = new GalleryController();
}

@Override
public void tearDown() {
GWTMockUtilities.restore();
}

public void testCreateView() {
Dispatcher dispatcher = Dispatcher.get();
dispatcher.addController(galleryController);
dispatcher.dispatch(AppEvents.ViewGallery);
assertNotNull(galleryController.galleryView);
assertTrue(galleryController.galleryView.isVisible());
}


Unfortunately, I get the following error when running the test:



java.lang.ExceptionInInitializerError
at com.extjs.gxt.ui.client.mvc.Dispatcher.<init>(Dispatcher.java:124)
at com.extjs.gxt.ui.client.mvc.Dispatcher.get(Dispatcher.java:111)
at org.richresume.client.gallery.GalleryControllerGwtTest.testCreateView(GalleryControllerGwtTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
Caused by: java.lang.NullPointerException
at com.google.gwt.user.client.History.<clinit>(History.java:61)
... 21 more


History.java:61 is the 3nd line in the following code.



static {
impl = GWT.create(HistoryImpl.class);
if (!impl.init()) {
// Set impl to null as a flag to no-op future calls.
impl = null;

// Tell the user.
GWT.log("Unable to initialize the history subsystem; did you "
+ "include the history frame in your host page? Try "
+ "<iframe src=\"javascript:''\" id='__gwt_historyFrame' "
+ "style='position:absolute;width:0;height:0;border:0'>"
+ "</iframe>", null);
}
}


Any ideas? Has anyone used GWTMockUtilities successfully?

sdc
17 Feb 2009, 6:48 AM
As said in GWTMockUtilities javadoc, when you "disarm", GWT.create will always return null -> NullPointerException in History:61.

eugenparaschiv
9 Nov 2009, 10:16 AM
Yes, so keeping that in mind:
http://www.extjs.com/forum/showthread.php?p=406825#post406825