public class

GWTMockUtilities

extends Object
java.lang.Object
   ↳ com.google.gwt.junit.GWTMockUtilities

Class Overview

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

Summary

Public Constructors
GWTMockUtilities()
Public Methods
static void disarm()
Replace the normal GWT.create() behavior with a method that returns null instead of throwing a runtime exception.
static void restore()
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public GWTMockUtilities ()

Public Methods

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);
 }
 

public static void restore ()