/** * Causes all calls to GWT.create to be intercepted to return a mock or fake * object, and populates any {@link 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 * {@link MockitoAnnotations#initMocks}, so there is no need to call that * method separately. See the class description for more details. * * @param owner class to scan for {@link GwtMock}-annotated fields - almost * always "this" in unit tests */ public static void initMocks(Object owner) { // Create a new bridge and register built-in type providers bridge = new Bridge(); for (Entry<Class<?>, FakeProvider<?>> entry : DEFAULT_FAKE_PROVIDERS.entrySet()) { useProviderForType(entry.getKey(), entry.getValue()); } // Install the bridge and populate mock fields boolean success = false; try { setGwtBridge(bridge); registerGwtMocks(owner); MockitoAnnotations.initMocks(owner); success = true; } finally { if (!success) { tearDown(); } } }
/** * Causes all calls to GWT.create to be intercepted to return a mock or fake * object, and populates any {@link 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 * {@link MockitoAnnotations#initMocks}, so there is no need to call that * method separately. See the class description for more details. * * @param owner class to scan for {@link GwtMock}-annotated fields - almost * always "this" in unit tests */ public static void initMocks(Object owner) { // Create a new bridge and register built-in type providers bridge = new Bridge(); for (Entry<Class<?>, FakeProvider<?>> entry : DEFAULT_FAKE_PROVIDERS.entrySet()) { useProviderForType(entry.getKey(), entry.getValue()); } // Install the bridge and populate mock fields boolean success = false; try { setGwtBridge(bridge); registerGwtMocks(owner); MockitoAnnotations.initMocks(owner); success = true; } finally { if (!success) { tearDown(); } } }