本文整理汇总了Java中com.google.gwtmockito.fakes.FakeProvider类的典型用法代码示例。如果您正苦于以下问题:Java FakeProvider类的具体用法?Java FakeProvider怎么用?Java FakeProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FakeProvider类属于com.google.gwtmockito.fakes包,在下文中一共展示了FakeProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setup
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Before
public void setup() {
imageAnchorMock = mock(ImageAnchor.class);
GwtMockito.useProviderForType(ImageAnchor.class,
new FakeProvider<ImageAnchor>() {
@Override
public ImageAnchor getFake(Class<?> aClass) {
return imageAnchorMock;
}
});
commentRow = new CommentRowWidget() {
@Override
SocialUserImageProvider getSocialUserImageProvider() {
final SocialUserImageProvider provider = mock(SocialUserImageProvider.class);
when(provider.getImageForSocialUser(any(SocialUser.class),
any(
SocialUserImageRepositoryAPI.ImageSize.class))).thenReturn(mock(Image.class));
return provider;
}
};
commentRow.left = new FlowPanel();
updateItem = new UpdateItem(new SocialActivitiesEvent(new SocialUser("dora"),
"",
new Date()));
}
开发者ID:kiegroup,项目名称:appformer,代码行数:27,代码来源:CommentRowWidgetTest.java
示例2: setup
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Before
public void setup() {
GwtMockito.useProviderForType(SimpleEventBus.class,
new FakeProvider() {
@Override
public Object getFake(Class aClass) {
return simpleEventBus;
}
});
ctx = mock(ModalConfigurationContext.class);
cleanupPlaceRequest = mock(Command.class);
editScreen = spy(new EditScreenFake(ctx,
cleanupPlaceRequest));
when(editScreen.addHiddenHandler(Mockito.any(ModalHiddenHandler.class))).thenAnswer(new Answer() {
public Object answer(InvocationOnMock aInvocation) throws Throwable {
modalHiddenHandler = (ModalHiddenHandler) aInvocation.getArguments()[0];
return null;
}
});
editScreen.realAddHiddenHandler();
}
开发者ID:kiegroup,项目名称:appformer,代码行数:25,代码来源:EditScreenTest.java
示例3: setUp
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// Mock The ListBox with loaded choices
GwtMockito.useProviderForType(ListBox.class, new FakeProvider<ListBox>() {
@Override
public ListBox getFake(Class<?> aClass) {
return choices;
}
});
// Mock partially the AsyncPackageDataModelOracle
incrementalDataModelServiceCaller = new CallerMock<>(incrementalDataModelService);
validatorInstance = new MockInstanceImpl<>();
oracle = spy(new AsyncPackageDataModelOracleImpl(incrementalDataModelServiceCaller, validatorInstance));
// Mock partially the AsyncPackageDataModelOracleFactory
doReturn(syncBeanDef).when(syncBeanManager).lookupBean(AsyncPackageDataModelOracle.class);
doReturn(oracle).when(syncBeanDef).getInstance();
}
开发者ID:kiegroup,项目名称:drools-wb,代码行数:20,代码来源:RuleModellerConditionSelectorPopupTest.java
示例4: fakeProvider
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
private FakeProvider<GuidedRuleEditorResources> fakeProvider() {
return provider -> new GuidedRuleEditorResources() {
@Override
public ItemImages itemImages() {
return mock(ItemImages.class);
}
@Override
public GuidedRuleEditorCss css() {
return mock(GuidedRuleEditorCss.class);
}
@Override
public GuidedRuleEditorImages images() {
return mock(GuidedRuleEditorImages.class);
}
};
}
开发者ID:kiegroup,项目名称:drools-wb,代码行数:19,代码来源:OperatorPageTest.java
示例5: initMocks
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
/**
* 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();
}
}
}
开发者ID:google,项目名称:gwtmockito,代码行数:32,代码来源:GwtMockito.java
示例6: shouldUseFakeIfProvided
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test
public void shouldUseFakeIfProvided() {
GwtMockito.useProviderForType(
TestRemoteService.class,
new FakeProvider<TestRemoteServiceAsync>() {
@Override
public TestRemoteServiceAsync getFake(Class<?> type) {
TestRemoteServiceAsync mock = mock(TestRemoteServiceAsync.class);
doAnswer(returnSuccess("faked")).when(mock).doRpcWithoutArgs(anyAsyncCallback());
return mock;
}
});
MyWidget widget = new MyWidget();
verify(widget.message).setText("faked");
}
开发者ID:google,项目名称:gwtmockito,代码行数:17,代码来源:GwtMockitoRpcWithoutGwtMockTest.java
示例7: gwtMockShouldTakePriorityOverFakes
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test
public void gwtMockShouldTakePriorityOverFakes() {
doAnswer(returnSuccess("mocked")).when(service).doRpcWithoutArgs(anyAsyncCallback());
GwtMockito.useProviderForType(
TestRemoteService.class,
new FakeProvider<TestRemoteServiceAsync>() {
@Override
public TestRemoteServiceAsync getFake(Class<?> type) {
TestRemoteServiceAsync mock = mock(TestRemoteServiceAsync.class);
doAnswer(returnSuccess("faked")).when(mock).doRpcWithoutArgs(anyAsyncCallback());
return mock;
}
});
MyWidgetWithoutArgs widget = new MyWidgetWithoutArgs();
verify(widget.message).setText("mocked");
}
开发者ID:google,项目名称:gwtmockito,代码行数:19,代码来源:GwtMockitoRpcTest.java
示例8: canUseProvidersForTypes
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test
public void canUseProvidersForTypes() {
GwtMockito.useProviderForType(AnotherInterface.class, new FakeProvider<AnotherInterface>() {
@Override
public AnotherInterface getFake(Class<?> type) {
return new AnotherInterface() {
@Override
public String doSomethingElse() {
return "some value";
}
};
}
});
AnotherInterface result = GWT.create(AnotherInterface.class);
assertEquals("some value", result.doSomethingElse());
}
开发者ID:google,项目名称:gwtmockito,代码行数:19,代码来源:GwtMockitoTest.java
示例9: getFakeShouldReturnRegisteredFakes
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test
public void getFakeShouldReturnRegisteredFakes() {
GwtMockito.useProviderForType(
AnotherInterface.class,
new FakeProvider<AnotherInterface>() {
@Override
public AnotherInterface getFake(Class<?> type) {
AnotherInterface mock = mock(AnotherInterface.class);
when(mock.doSomethingElse()).thenReturn("string");
return mock;
}});
AnotherInterface fake = GwtMockito.getFake(AnotherInterface.class);
assertEquals("string", fake.doSomethingElse());
}
开发者ID:google,项目名称:gwtmockito,代码行数:17,代码来源:GwtMockitoTest.java
示例10: setup
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Before
public void setup() throws Exception {
mockTimer();
GwtMockito.useProviderForType(WorkbenchResources.class,
new FakeProvider<WorkbenchResources>() {
@Override
public WorkbenchResources getFake(Class<?> type) {
return null;
}
});
final Runnable reloadRunnable = new Runnable() {
@Override
public void run() {
reloads++;
}
};
final TitleProvider titleProvider = new TitleProvider() {
@Override
public String getTitle() {
return "";
}
};
target = new LockTarget(path,
widget,
new DefaultPlaceRequest("mockPlace"),
titleProvider,
reloadRunnable);
lockManager.init(target);
when(user.getIdentifier()).thenReturn("mockedUser");
when(lockDemandDetector.isLockRequired(any(Event.class))).thenReturn(true);
}
开发者ID:kiegroup,项目名称:appformer,代码行数:41,代码来源:LockManagerTest.java
示例11: setUp
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
GwtMockito.initMocks(this);
GwtMockito.useProviderForType(ViewEngine.WidgetBindingMap.class, new FakeProvider<Object>() {
@Override
public Object getFake(Class<?> type) {
return new WidgetBindingMapForTest();
}
});
}
开发者ID:growbit,项目名称:turbogwt-databind,代码行数:12,代码来源:DatabindViewEngineTest.java
示例12: useProviderForType
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
/**
* Specifies that the given provider should be used to GWT.create instances of
* the given type and its subclasses. If multiple providers could produce a
* given class (for example, if a provide is registered for a type and its
* supertype), the provider for the more specific type is chosen. An exception
* is thrown if this type is ambiguous. Note that if you just want to return a
* Mockito mock from GWT.create, it's probably easier to use {@link GwtMock}
* instead.
*/
public static void useProviderForType(Class<?> type, FakeProvider<?> provider) {
if (bridge == null) {
throw new IllegalStateException("Must call initMocks() before calling useProviderForType()");
}
if (bridge.registeredMocks.containsKey(type)) {
throw new IllegalArgumentException(
"Can't use a provider for a type that already has a @GwtMock declared");
}
bridge.registeredProviders.put(type, provider);
}
开发者ID:google,项目名称:gwtmockito,代码行数:20,代码来源:GwtMockito.java
示例13: typeProvidersShouldWorkForSubtypes
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test
public void typeProvidersShouldWorkForSubtypes() {
final Widget someWidget = mock(Widget.class);
GwtMockito.useProviderForType(Widget.class, new FakeProvider<Widget>() {
@Override
public Widget getFake(Class<?> type) {
assertTrue(type == Label.class);
return someWidget;
}
});
assertSame(someWidget, GWT.create(Label.class));
}
开发者ID:google,项目名称:gwtmockito,代码行数:15,代码来源:GwtMockitoTest.java
示例14: shouldNotAllowProvidersForGwtMockedTypes
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowProvidersForGwtMockedTypes() {
GwtMockito.useProviderForType(SampleInterface.class, new FakeProvider<SampleInterface>() {
@Override
public SampleInterface getFake(Class<?> type) {
return mock(SampleInterface.class);
}
});
}
开发者ID:google,项目名称:gwtmockito,代码行数:10,代码来源:GwtMockitoTest.java
示例15: getFakeFromProviderMap
import com.google.gwtmockito.fakes.FakeProvider; //导入依赖的package包/类
private static <T> T getFakeFromProviderMap(Class<T> type, Map<Class<?>, FakeProvider<?>> map) {
// See if we have any providers for this type or its supertypes.
Map<Class<?>, FakeProvider<?>> legalProviders = new HashMap<Class<?>, FakeProvider<?>>();
for (Entry<Class<?>, FakeProvider<?>> entry : map.entrySet()) {
if (entry.getKey().isAssignableFrom(type)) {
legalProviders.put(entry.getKey(), entry.getValue());
}
}
// Filter the set of legal providers to the most specific type.
Map<Class<?>, FakeProvider<?>> filteredProviders = new HashMap<Class<?>, FakeProvider<?>>();
for (Entry<Class<?>, FakeProvider<?>> candidate : legalProviders.entrySet()) {
boolean isSpecific = true;
for (Entry<Class<?>, FakeProvider<?>> other : legalProviders.entrySet()) {
if (candidate != other && candidate.getKey().isAssignableFrom(other.getKey())) {
isSpecific = false;
break;
}
}
if (isSpecific) {
filteredProviders.put(candidate.getKey(), candidate.getValue());
}
}
// If exactly one provider remains, use it.
if (filteredProviders.size() == 1) {
// We know this is safe since we checked that the types are assignable
@SuppressWarnings({"rawtypes", "cast"})
Class rawType = (Class) type;
return (T) filteredProviders.values().iterator().next().getFake(rawType);
} else if (filteredProviders.isEmpty()) {
return null;
} else {
throw new IllegalArgumentException("Can't decide which provider to use for " +
type.getSimpleName() +
", it could be provided as any of the following: " +
mapToSimpleNames(filteredProviders.keySet()) +
". Add a provider for " +
type.getSimpleName() +
" to resolve this ambiguity.");
}
}
开发者ID:google,项目名称:gwtmockito,代码行数:43,代码来源:GwtMockito.java
注:本文中的com.google.gwtmockito.fakes.FakeProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论