|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.gwtmockito.GwtMockito
public class GwtMockito
A library to make Mockito-based testing of GWT applications easier. Most
users won't have to reference this class directly and should instead use
GwtMockitoTestRunner
. Users who cannot use that class (e.g. tests
using JUnit3) can invoke initMocks(java.lang.Object)
directly in their setUp and
tearDown()
in their tearDown methods.
Note that calling initMocks(java.lang.Object)
and tearDown()
directly does
not implement GwtMockitoTestRunner
's behavior of implementing
native methods and making final methods mockable. The only way to get this
behavior is by using GwtMockitoTestRunner
.
Once initMocks(java.lang.Object)
has been invoked, test code can safely call
GWT.create without exceptions. Doing so will return either a mock object
registered with GwtMock
, a fake object specified by a call to
useProviderForType(java.lang.Class>, com.google.gwtmockito.fakes.FakeProvider>)
, or a new mock instance if no other binding
exists. Fakes for types extending the following are provided by default:
FakeUiBinderProvider
for details.
FakeClientBundleProvider
for details.
FakeMessagesProvider
for details.
The type returned from GWT.create will generally be the same as the type
passed in. The exception is when GWT.create'ing a subclass of
RemoteService
- in this case, the result of GWT.create will be the
Async version of that interface as defined by gwt-rpc.
If initMocks(java.lang.Object)
is called manually, it is important to invoke
tearDown()
once the test has been completed. Failure to do so can
cause state to leak between tests.
GwtMockitoTestRunner
,
GwtMock
Constructor Summary | |
---|---|
GwtMockito()
|
Method Summary | |
---|---|
static void |
initMocks(Object owner)
Causes all calls to GWT.create to be intercepted to return a mock or fake object, and populates any GwtMock -annotated fields with mockito
mocks. |
static void |
tearDown()
Resets GWT.create to its default behavior. |
static void |
useProviderForType(Class<?> type,
FakeProvider<?> provider)
Specifies that the given provider should be used to GWT.create instances of the given type and its subclasses. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GwtMockito()
Method Detail |
---|
public static void initMocks(Object owner)
GwtMock
-annotated fields with mockito
mocks. This method should be usually be called during the setUp method of a
test case. Note that it explicitly calls
MockitoAnnotations.initMocks(java.lang.Object)
, so there is no need to call that
method separately. See the class description for more details.
owner
- class to scan for GwtMock
-annotated fields - almost
always "this" in unit testspublic static void tearDown()
public static void useProviderForType(Class<?> type, FakeProvider<?> provider)
GwtMock
instead.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |