com.google.gwt.user.client.rpc.RemoteService Java Examples

The following examples show how to use com.google.gwt.user.client.rpc.RemoteService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GwtMockito.java    From gwtmockito with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked") // safe since we check whether the type is assignable
public <T> T create(Class<?> createdType) {
  // If we're creating a RemoteService, assume that the result of GWT.create is being assigned
  // to the async version of that service. Otherwise, assume it's being assigned to the same
  // type we're creating.
  Class<?> assignedType = RemoteService.class.isAssignableFrom(createdType)
      ? getAsyncType((Class<? extends RemoteService>) createdType)
      : createdType;

  // First check if we have a GwtMock for this exact being assigned to and use it if so.
  if (registeredMocks.containsKey(assignedType)) {
    return (T) registeredMocks.get(assignedType);
  }

  // Next check if we have a fake provider that can provide a fake for the type being created.
  T fake = (T) getFakeFromProviderMap(createdType, registeredProviders);
  if (fake != null) {
    return fake;
  }

  // If nothing has been registered, just return a new mock for the type being assigned.
  return (T) mock(assignedType, new ReturnsCustomMocks());
}
 
Example #2
Source File: GwtMockito.java    From gwtmockito with Apache License 2.0 5 votes vote down vote up
/** Returns the corresponding async service type for the given remote service type. */
private Class<?> getAsyncType(Class<? extends RemoteService> type) {
  Class<?> asyncType;
  try {
    asyncType = Class.forName(type.getCanonicalName() + "Async");
  } catch (ClassNotFoundException e) {
    throw new IllegalArgumentException(
        type.getCanonicalName() + " does not have a corresponding async interface", e);
  }
  return asyncType;
}