本文整理汇总了Java中org.easymock.classextension.EasyMock类的典型用法代码示例。如果您正苦于以下问题:Java EasyMock类的具体用法?Java EasyMock怎么用?Java EasyMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EasyMock类属于org.easymock.classextension包,在下文中一共展示了EasyMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCallMethod
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
/** Tests Service.callMethod(). */
public void testCallMethod() throws Exception {
FooRequest fooRequest = FooRequest.newBuilder().build();
BarRequest barRequest = BarRequest.newBuilder().build();
MockCallback<Message> fooCallback = new MockCallback<Message>();
MockCallback<Message> barCallback = new MockCallback<Message>();
TestService mockService = control.createMock(TestService.class);
mockService.foo(EasyMock.same(mockController), EasyMock.same(fooRequest),
this.<FooResponse>wrapsCallback(fooCallback));
mockService.bar(EasyMock.same(mockController), EasyMock.same(barRequest),
this.<BarResponse>wrapsCallback(barCallback));
control.replay();
mockService.callMethod(fooDescriptor, mockController,
fooRequest, fooCallback);
mockService.callMethod(barDescriptor, mockController,
barRequest, barCallback);
control.verify();
}
示例2: testNewReflectiveBlockingService
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testNewReflectiveBlockingService() throws ServiceException {
ServiceWithNoOuter.BlockingInterface impl =
control.createMock(ServiceWithNoOuter.BlockingInterface.class);
RpcController controller = control.createMock(RpcController.class);
BlockingService service =
ServiceWithNoOuter.newReflectiveBlockingService(impl);
MethodDescriptor fooMethod =
ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
.andReturn(expectedResponse);
control.replay();
Message response =
service.callBlockingMethod(fooMethod, controller, request);
assertEquals(expectedResponse, response);
control.verify();
}
示例3: testLaziness
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testLaziness() throws InvalidProtocolBufferException {
LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
.setNum(2)
.build();
LazyMessageLite outer = LazyMessageLite.newBuilder()
.setNum(1)
.setInner(inner)
.setOneofInner(inner)
.build();
ByteString bytes = outer.toByteString();
// The parser for inner / oneofInner message shouldn't be used if
// getInner / getOneofInner is not called.
LazyInnerMessageLite.PARSER = EasyMock.createStrictMock(Parser.class);
EasyMock.replay(LazyInnerMessageLite.PARSER);
LazyMessageLite deserialized = LazyMessageLite.parseFrom(bytes);
assertEquals(1, deserialized.getNum());
assertEquals(421, deserialized.getNumWithDefault());
EasyMock.verify(LazyInnerMessageLite.PARSER);
}
示例4: testSetCharacterEncoding_allowsExceptionToPassBack
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
@Test
public void testSetCharacterEncoding_allowsExceptionToPassBack()
throws UnsupportedEncodingException {
final UnsupportedEncodingException expected
= new UnsupportedEncodingException();
mockSubset.setCharacterEncoding(EasyMock.eq(VALUE));
EasyMock.expectLastCall().andThrow(expected);
EasyMock.replay(mockSubset);
try {
adapter.setCharacterEncoding(VALUE);
fail("Should pass exception through");
} catch (UnsupportedEncodingException actual) {
assertThat(actual, sameInstance(expected));
}
EasyMock.verify(mockSubset);
}
示例5: testRunCallsQueuedRunnables
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testRunCallsQueuedRunnables() throws Exception {
RunnableQueue q = EasyMock.createMock(RunnableQueue.class);
Runnable task1 = EasyMock.createMock(Runnable.class);
Runnable task2 = EasyMock.createMock(Runnable.class);
EasyMock.expect(q.remove()).andReturn(task1);
task1.run();
EasyMock.expectLastCall();
EasyMock.expect(q.remove()).andReturn(task2);
task2.run();
EasyMock.expectLastCall();
EasyMock.expect(q.remove()).andThrow(new InterruptedException());
EasyMock.replay(q, task1, task2);
QueueExtractor extractor = new QueueExtractor(q);
extractor.run();
EasyMock.verify(q, task1, task2);
}
示例6: testRun
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testRun() throws Exception {
RunnableQueue q = EasyMock.createMock(RunnableQueue.class);
Runnable task1 = EasyMock.createMock(Runnable.class);
Runnable task2 = EasyMock.createMock(Runnable.class);
EasyMock.expect(q.remove()).andReturn(task1);
task1.run();
EasyMock.expectLastCall();
EasyMock.expect(q.remove()).andReturn(task2);
task2.run();
EasyMock.expectLastCall();
EasyMock.expect(q.remove()).andThrow(new InterruptedException());
EasyMock.replay(q, task1, task2);
WorkerThread worker = new WorkerThread(q, "test thread");
worker.run();
EasyMock.verify(q, task1, task2);
}
示例7: testGetEntryInvalidUrl
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testGetEntryInvalidUrl() throws Exception {
// Setup
URL badUrl = new URL("http://badUrl");
String errorMsg = "invalid URL";
EasyMock.expect(mockService.getEntry(badUrl, FeedServerEntry.class)).andThrow(
new IOException(errorMsg));
EasyMock.replay(mockService);
// Perform Test
try {
@SuppressWarnings("unused")
Map<String, Object> fetchedMap = feedServerClient.getEntry(badUrl);
} catch (FeedServerClientException e) {
assertTrue(e.getCause().getMessage().equals(errorMsg));
EasyMock.verify(mockService);
return;
}
fail("Did not get FeedServerClientException");
}
示例8: testCheckAccessSuccessOnRetrieveEntry
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testCheckAccessSuccessOnRetrieveEntry() throws Exception {
String[][] principalx = new String[][] {
new String[]{USER1_EMAIL}, new String[]{USER1_EMAIL, USER2_EMAIL}};
for (String[] principals: principalx) {
prepare(new AdapterCall() {
@Override
public void invoke(AbstractManagedCollectionAdapter adapter)
throws FeedServerAdapterException {
EasyMock.expect(adapter.retrieveEntry(isA(RequestContext.class), isA(Object.class)))
.andReturn(null);
}
});
ResourceConnectionInfoWrapper aclWrapper =
new ResourceConnectionInfoWrapper(targetAdapterMock, getWrapperConfig(
AuthorizedEntity.OPERATION_RETRIEVE, principals));
aclWrapper.retrieveEntry(requestMock, "123");
finish();
}
}
示例9: prepare
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
protected void prepare(AdapterCall adapterCall) throws Exception {
targetAdapterMock = EasyMock.createMock(AbstractManagedCollectionAdapter.class);
requestMock = EasyMock.createMock(RequestContext.class);
userInfoMock = EasyMock.createMock(UserInfo.class);
entryMock = EasyMock.createMock(Entry.class);
EasyMock.expect(targetAdapterMock.getAbdera()).andReturn(null);
EasyMock.expect(targetAdapterMock.getConfiguration()).andReturn(null);
EasyMock.expect(requestMock.getAttribute(
RequestContext.Scope.REQUEST, AbstractManagedCollectionAdapter.USER_INFO))
.andReturn(userInfoMock);
EasyMock.expect(userInfoMock.getEmail()).andReturn(USER1_EMAIL);
adapterCall.invoke(targetAdapterMock);
EasyMock.replay(targetAdapterMock);
EasyMock.replay(requestMock);
EasyMock.replay(userInfoMock);
EasyMock.replay(entryMock);
}
示例10: testGetEntryInvalidUrl
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testGetEntryInvalidUrl() throws Exception {
// Setup
URL badUrl = new URL("http://badUrl");
String errorMsg = "invalid URL";
EasyMock.expect(mockService.getEntry(badUrl, FeedServerEntry.class)).andThrow(
new IOException(errorMsg));
EasyMock.replay(mockService);
// Perform Test
try {
feedServerClient.getEntity(badUrl);
} catch (FeedServerClientException e) {
assertTrue(e.getCause().getMessage().equals(errorMsg));
EasyMock.verify(mockService);
return;
}
fail("Did not get FeedServerClientException");
}
示例11: testStub
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
/** Tests generated stubs. */
public void testStub() throws Exception {
FooRequest fooRequest = FooRequest.newBuilder().build();
BarRequest barRequest = BarRequest.newBuilder().build();
MockCallback<FooResponse> fooCallback = new MockCallback<FooResponse>();
MockCallback<BarResponse> barCallback = new MockCallback<BarResponse>();
RpcChannel mockChannel = control.createMock(RpcChannel.class);
TestService stub = TestService.newStub(mockChannel);
mockChannel.callMethod(
EasyMock.same(fooDescriptor),
EasyMock.same(mockController),
EasyMock.same(fooRequest),
EasyMock.same(FooResponse.getDefaultInstance()),
this.<Message>wrapsCallback(fooCallback));
mockChannel.callMethod(
EasyMock.same(barDescriptor),
EasyMock.same(mockController),
EasyMock.same(barRequest),
EasyMock.same(BarResponse.getDefaultInstance()),
this.<Message>wrapsCallback(barCallback));
control.replay();
stub.foo(mockController, fooRequest, fooCallback);
stub.bar(mockController, barRequest, barCallback);
control.verify();
}
示例12: testBlockingStub
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
/** Tests generated blocking stubs. */
public void testBlockingStub() throws Exception {
FooRequest fooRequest = FooRequest.newBuilder().build();
BarRequest barRequest = BarRequest.newBuilder().build();
BlockingRpcChannel mockChannel =
control.createMock(BlockingRpcChannel.class);
TestService.BlockingInterface stub =
TestService.newBlockingStub(mockChannel);
FooResponse fooResponse = FooResponse.newBuilder().build();
BarResponse barResponse = BarResponse.newBuilder().build();
EasyMock.expect(mockChannel.callBlockingMethod(
EasyMock.same(fooDescriptor),
EasyMock.same(mockController),
EasyMock.same(fooRequest),
EasyMock.same(FooResponse.getDefaultInstance()))).andReturn(fooResponse);
EasyMock.expect(mockChannel.callBlockingMethod(
EasyMock.same(barDescriptor),
EasyMock.same(mockController),
EasyMock.same(barRequest),
EasyMock.same(BarResponse.getDefaultInstance()))).andReturn(barResponse);
control.replay();
assertSame(fooResponse, stub.foo(mockController, fooRequest));
assertSame(barResponse, stub.bar(mockController, barRequest));
control.verify();
}
示例13: testNewReflectiveService
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testNewReflectiveService() {
ServiceWithNoOuter.Interface impl =
control.createMock(ServiceWithNoOuter.Interface.class);
RpcController controller = control.createMock(RpcController.class);
Service service = ServiceWithNoOuter.newReflectiveService(impl);
MethodDescriptor fooMethod =
ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
RpcCallback<Message> callback = new RpcCallback<Message>() {
public void run(Message parameter) {
// No reason this should be run.
fail();
}
};
RpcCallback<TestAllTypes> specializedCallback =
RpcUtil.specializeCallback(callback);
impl.foo(EasyMock.same(controller), EasyMock.same(request),
EasyMock.same(specializedCallback));
EasyMock.expectLastCall();
control.replay();
service.callMethod(fooMethod, controller, request, callback);
control.verify();
}
示例14: testNewReflectiveBlockingService
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
public void testNewReflectiveBlockingService() throws ServiceException {
ServiceWithNoOuter.BlockingInterface impl =
control.createMock(ServiceWithNoOuter.BlockingInterface.class);
RpcController controller = control.createMock(RpcController.class);
BlockingService service =
ServiceWithNoOuter.newReflectiveBlockingService(impl);
MethodDescriptor fooMethod =
ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
RpcCallback<Message> callback = new RpcCallback<Message>() {
public void run(Message parameter) {
// No reason this should be run.
fail();
}
};
TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
.andReturn(expectedResponse);
control.replay();
Message response =
service.callBlockingMethod(fooMethod, controller, request);
assertEquals(expectedResponse, response);
control.verify();
}
示例15: testRest
import org.easymock.classextension.EasyMock; //导入依赖的package包/类
@Test
public void testRest() throws Exception {
MockTest mockTest = new MockTest();
easyMockModule.createAndInjectMocksIntoTest(mockTest);
EasyMock.expect(mockTest.testMock.isEmpty()).andReturn(Boolean.TRUE);
easyMockModule.reset(); //without the reset the call would fail.
easyMockModule.verify();
}