com.google.gwt.junit
Class GWTMockUtilities

java.lang.Object
  extended by com.google.gwt.junit.GWTMockUtilities

public class GWTMockUtilities
extends java.lang.Object

Defangs GWT.create(Class) to allow unit tests to mock out Widgets and other UIObjects.


Constructor Summary
GWTMockUtilities()
           
 
Method Summary
static void disarm()
          Replace the normal GWT.create() behavior with a method that returns null instead of throwing a runtime exception.
static void restore()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GWTMockUtilities

public GWTMockUtilities()
Method Detail

disarm

public static void disarm()
Replace the normal GWT.create() behavior with a method that returns null instead of throwing a runtime exception. This is to allow JUnit tests to mock classes that make GWT.create() calls in their static initializers. This is not for use with GWTTestCase, and is not for use testing widgets themselves. Rather, it is to allow pure java unit tests of classes that need to manipulate widgets.

NOTE: Be sure to call restore() in your tearDown method, to avoid confusing downstream tests.

Sample use:

@Override
 public void setUp() throws Exception {
   super.setUp();
   GWTMockUtilities.disarm();
 }

 @Override
 public void tearDown() {
   GWTMockUtilities.restore();
 }
 
 public void testSomething() {
   MyStatusWidget mock = EasyMock.createMock(MyStatusWidget.class);
   EasyMock.expect(mock.setText("expected text"));
   EasyMock.replay(mock);
   
   StatusController controller = new StatusController(mock);
   controller.setStatus("expected text");
   
   EasyMock.verify(mock);
 }
 


restore

public static void restore()