Tabnine Logo
GwtMockito
Code IndexAdd Tabnine to your IDE (free)

How to use
GwtMockito
in
com.google.gwtmockito

Best Java code snippets using com.google.gwtmockito.GwtMockito (Showing top 20 results out of 315)

origin: kiegroup/appformer

@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;
  }});
}
origin: org.kie.workbench.widgets/kie-wb-decorated-grid-widget

@Before
public void setUp() {
  GwtMockito.initMocks(this);
}
origin: com.google.gwt.gwtmockito/gwtmockito

/**
 * 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;
}
origin: com.google.gwt.gwtmockito/gwtmockito

/**
 * 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();
  }
 }
}
origin: google/gwtmockito

type.getSimpleName() +
", it could be provided as any of the following: " +
mapToSimpleNames(filteredProviders.keySet()) +
". Add a provider for " +
type.getSimpleName() +
origin: google/gwtmockito

/**
 * 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();
  }
 }
}
origin: com.google.gwt.gwtmockito/gwtmockito

type.getSimpleName() +
", it could be provided as any of the following: " +
mapToSimpleNames(filteredProviders.keySet()) +
". Add a provider for " +
type.getSimpleName() +
origin: kiegroup/drools-wb

@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();
}
origin: org.kie.workbench.screens/kie-wb-common-project-explorer-client

@Before
public void setUp() throws Exception {
  GwtMockito.initMocks( this );
  changedEvent = spy( new EventSourceMock<ActiveOptionsChangedEvent>() {
    @Override
    public void fire( ActiveOptionsChangedEvent event ) {
    }
  } );
}
origin: google/gwtmockito

/**
 * 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;
}
origin: kiegroup/drools-wb

private void registerFakeProvider() {
  GwtMockito.useProviderForType(GuidedRuleEditorResources.class,
                 fakeProvider());
}
origin: org.guvnor/guvnor-structure-client

@Before
public void init() {
  GwtMockito.initMocks(this);
  btn = GWT.create(CopyRepositoryUrlBtn.class);
  doCallRealMethod().when(btn).init(anyBoolean(),
                   anyString(),
                   anyString());
}
origin: org.drools/drools-wb-guided-rule-editor-client

@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();
}
origin: kiegroup/appformer

@Before
public void init() {
  GwtMockito.initMocks(this);
  btn = GWT.create(CopyRepositoryUrlBtn.class);
  doCallRealMethod().when(btn).init(anyBoolean(),
                   anyString(),
                   anyString());
}
origin: org.kie.workbench.stunner/kie-wb-common-stunner-project-client

@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());
}
origin: kiegroup/drools-wb

@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);
}
origin: org.drools/drools-wb-guided-rule-editor-client

@Before
public void setUp() throws Exception {
  GwtMockito.useProviderForType(GuidedRuleAttributeSelectorPopup.class,
                 (aClass) -> guidedRuleAttributeSelectorPopup);
  doReturn(addImage).when(addAttributeWidget).asWidget();
}
origin: kiegroup/drools-wb

@Before
public void setUp() throws Exception {
  GwtMockito.useProviderForType(GuidedRuleAttributeSelectorPopup.class,
                 (aClass) -> guidedRuleAttributeSelectorPopup);
  doReturn(addImage).when(addAttributeWidget).asWidget();
}
origin: kiegroup/drools-wb

@Before
public void setUp() throws Exception {
  testedLayout = spy(new FixtureLayout());
  GwtMockito.useProviderForType(DeleteExecutionTraceButton.class, aClass -> deleteExecutionTraceButton);
}
origin: org.drools/drools-wb-test-scenario-editor-client

@Before
public void setUp() throws Exception {
  testedLayout = spy(new FixtureLayout());
  GwtMockito.useProviderForType(DeleteExecutionTraceButton.class, aClass -> deleteExecutionTraceButton);
}
com.google.gwtmockitoGwtMockito

Javadoc

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 directly in their setUp and #tearDown in their tearDown methods.

Note that calling #initMocks 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 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, or a new mock instance if no other binding exists. Fakes for types extending the following are provided by default:

  • UiBinder: uses a fake that populates all UiFields with GWT.create'd widgets, allowing them to be mocked like other calls to GWT.create. See FakeUiBinderProvider for details.
  • ClientBundle: Uses a fake that will return fake CssResources as defined below, and will return fake versions of other resources that return unique strings for getText and getSafeUri. See FakeClientBundleProvider for details.
  • Messages, CssResource, and SafeHtmlTemplates: uses a fake that implements each method by returning a String of SafeHtml based on the name of the method and any arguments passed to it. The exact format is undefined. See 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 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.

Most used methods

  • useProviderForType
    Specifies that the given provider should be used to GWT.create instances of the given type and its s
  • initMocks
    Causes all calls to GWT.create to be intercepted to return a mock or fake object, and populates any
  • getFakeFromProviderMap
  • mapToSimpleNames
  • registerGwtMocks
  • setGwtBridge
  • tearDown
    Resets GWT.create to its default behavior. This method should be called after any test that called i

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getContentResolver (Context)
  • startActivity (Activity)
  • setContentView (Activity)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now