@Before public void setUp() throws Exception { GwtMockito.useProviderForType(FormLabel.class, aClass -> formLabel); GwtMockito.useProviderForType(FormLabelHelp.class, aClass -> formLabelHelp); testedItem = spy(new FormStyleItem() {{ labelContainer = FormStyleItemTest.this.labelContainer; group = FormStyleItemTest.this.group; }}); }
@Before public void setUp() { GwtMockito.initMocks(this); }
/** * Returns a new fake object of the given type assuming a fake provider is * available for that type. Additional fake providers can be registered via * {@link #useProviderForType}. * * @param type type to get a fake object for * @return a fake of the given type, as returned by an applicable provider * @throws IllegalArgumentException if no provider for the given type (or one * of its superclasses) has been registered */ public static <T> T getFake(Class<T> type) { // If initMocks hasn't been called, read from the default fake provider map. This allows static // fields to be initialized with fakes in tests that don't use the GwtMockito test runner. T fake = getFakeFromProviderMap( type, bridge != null ? bridge.registeredProviders : DEFAULT_FAKE_PROVIDERS); if (fake == null) { throw new IllegalArgumentException("No fake provider has been registered " + "for " + type.getSimpleName() + ". Call useProviderForType to " + "register a provider before calling getFake."); } return fake; }
/** * 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(); } } }
type.getSimpleName() + ", it could be provided as any of the following: " + mapToSimpleNames(filteredProviders.keySet()) + ". Add a provider for " + type.getSimpleName() +
/** * 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(); } } }
type.getSimpleName() + ", it could be provided as any of the following: " + mapToSimpleNames(filteredProviders.keySet()) + ". Add a provider for " + type.getSimpleName() +
@Before public void setUp() throws Exception { GwtMockito.useProviderForType(FormStyleLayout.class, aClass -> layout); GwtMockito.useProviderForType(DirtyableHorizontalPane.class, aClass -> dirtyableHorizontalPane); GwtMockito.useProviderForType(TextBox.class, aClass -> textBox); doReturn(textBoxElement).when(textBox).getElement(); doReturn(textBoxInputElement).when(textBoxElement).cast(); ruleModel = new RuleModel(); }
@Before public void setUp() throws Exception { GwtMockito.initMocks( this ); changedEvent = spy( new EventSourceMock<ActiveOptionsChangedEvent>() { @Override public void fire( ActiveOptionsChangedEvent event ) { } } ); }
/** * Returns a new fake object of the given type assuming a fake provider is * available for that type. Additional fake providers can be registered via * {@link #useProviderForType}. * * @param type type to get a fake object for * @return a fake of the given type, as returned by an applicable provider * @throws IllegalArgumentException if no provider for the given type (or one * of its superclasses) has been registered */ public static <T> T getFake(Class<T> type) { // If initMocks hasn't been called, read from the default fake provider map. This allows static // fields to be initialized with fakes in tests that don't use the GwtMockito test runner. T fake = getFakeFromProviderMap( type, bridge != null ? bridge.registeredProviders : DEFAULT_FAKE_PROVIDERS); if (fake == null) { throw new IllegalArgumentException("No fake provider has been registered " + "for " + type.getSimpleName() + ". Call useProviderForType to " + "register a provider before calling getFake."); } return fake; }
private void registerFakeProvider() { GwtMockito.useProviderForType(GuidedRuleEditorResources.class, fakeProvider()); }
@Before public void init() { GwtMockito.initMocks(this); btn = GWT.create(CopyRepositoryUrlBtn.class); doCallRealMethod().when(btn).init(anyBoolean(), anyString(), anyString()); }
@Before public void setUp() throws Exception { GwtMockito.useProviderForType(FormStyleLayout.class, aClass -> layout); GwtMockito.useProviderForType(DirtyableHorizontalPane.class, aClass -> dirtyableHorizontalPane); GwtMockito.useProviderForType(TextBox.class, aClass -> textBox); doReturn(textBoxElement).when(textBox).getElement(); doReturn(textBoxInputElement).when(textBoxElement).cast(); ruleModel = new RuleModel(); }
@Before public void init() { GwtMockito.initMocks(this); btn = GWT.create(CopyRepositoryUrlBtn.class); doCallRealMethod().when(btn).init(anyBoolean(), anyString(), anyString()); }
@Before public void setup() { GwtMockito.useProviderForType(AnchorListItem.class, aClass -> listItem); this.menuItemsBuilder = new AbstractProjectDiagramEditorMenuItemsBuilder(translationService, popupUtil) { @Override protected String getExportAsRawLabel() { return EXPORT_RAW; } }; when(translationService.getValue(anyString())).thenAnswer(i -> i.getArguments()[0].toString()); }
@Before public void setUp() { GwtMockito.initMocks(this); utilities = new ColumnUtilities(model, oracle); pattern = new Pattern52(); column = new ConditionCol52(); when(model.getPattern(column)).thenReturn(pattern); final Map<String, String> properties = new HashMap<>(); if (valueList.compareTo(DATE_CONVERSION_VALUE_LIST) == 0) { properties.put(ApplicationPreferences.DATE_FORMAT, "dd-MM-yyyy"); } else { properties.put(ApplicationPreferences.DATE_FORMAT, null); } ApplicationPreferences.setUp(properties); }
@Before public void setUp() throws Exception { GwtMockito.useProviderForType(GuidedRuleAttributeSelectorPopup.class, (aClass) -> guidedRuleAttributeSelectorPopup); doReturn(addImage).when(addAttributeWidget).asWidget(); }
@Before public void setUp() throws Exception { GwtMockito.useProviderForType(GuidedRuleAttributeSelectorPopup.class, (aClass) -> guidedRuleAttributeSelectorPopup); doReturn(addImage).when(addAttributeWidget).asWidget(); }
@Before public void setUp() throws Exception { testedLayout = spy(new FixtureLayout()); GwtMockito.useProviderForType(DeleteExecutionTraceButton.class, aClass -> deleteExecutionTraceButton); }
@Before public void setUp() throws Exception { testedLayout = spy(new FixtureLayout()); GwtMockito.useProviderForType(DeleteExecutionTraceButton.class, aClass -> deleteExecutionTraceButton); }