• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EasyMock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.easymock.classextension.EasyMock的典型用法代码示例。如果您正苦于以下问题:Java EasyMock类的具体用法?Java EasyMock怎么用?Java EasyMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EasyMock类属于org.easymock.classextension包,在下文中一共展示了EasyMock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:ServiceTest.java


示例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();
}
 
开发者ID:os72,项目名称:protobuf-java-shaded-261,代码行数:24,代码来源:ServiceTest.java


示例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);
}
 
开发者ID:os72,项目名称:protobuf-java-shaded-261,代码行数:25,代码来源:LazyMessageLiteTest.java


示例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);
}
 
开发者ID:bboypscmylife,项目名称:opengse,代码行数:17,代码来源:HttpServletRequestAdapterTest.java


示例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);
}
 
开发者ID:bboypscmylife,项目名称:opengse,代码行数:17,代码来源:QueueExtractorTest.java


示例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);
}
 
开发者ID:bboypscmylife,项目名称:opengse,代码行数:17,代码来源:WorkerThreadTest.java


示例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");
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:20,代码来源:TypelessFeedServerClientTest.java


示例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();
  }
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:22,代码来源:ResourceConnectionInfoWrapperTest.java


示例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);
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:20,代码来源:ResourceConnectionInfoWrapperTest.java


示例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");
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:19,代码来源:FeedServerClientTest.java


示例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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:28,代码来源:ServiceTest.java


示例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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:ServiceTest.java


示例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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:ServiceTest.java


示例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();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:30,代码来源:ServiceTest.java


示例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();
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:9,代码来源:EasyMockModuleTest.java


示例16: testEvaluateExceptionOnListener

import org.easymock.classextension.EasyMock; //导入依赖的package包/类
/**
 * Test method for {@link org.unitils.core.junit.BeforeTestMethodStatement#evaluate()}.
 */
@Test(expected = NullPointerException.class)
public void testEvaluateExceptionOnListener() throws Throwable {
    TestClass2 testObject = new TestClass2();
    Method testMethod = TestClass2.class.getMethod("test1");
    listener.beforeTestMethod(testObject, testMethod);
    EasyMock.expectLastCall().andThrow(new NullPointerException());

    EasyMockUnitils.replay();
    new BeforeTestMethodStatement(listener, statement, testMethod, testObject).evaluate();

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:15,代码来源:BeforeTestMethodStatementTest.java


示例17: testEvaluateExceptionOnStatement

import org.easymock.classextension.EasyMock; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testEvaluateExceptionOnStatement() throws Throwable {
    TestClass2 testObject = new TestClass2();
    Method testMethod = TestClass2.class.getMethod("test1");
    listener.beforeTestMethod(testObject, testMethod);
    statement.evaluate();
    EasyMock.expectLastCall().andThrow(new NullPointerException());

    EasyMockUnitils.replay();
    new BeforeTestMethodStatement(listener, statement, testMethod, testObject).evaluate();

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:13,代码来源:BeforeTestMethodStatementTest.java


示例18: testEvaluateExceptionOnListener

import org.easymock.classextension.EasyMock; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testEvaluateExceptionOnListener() throws Throwable {
    TestClass2 testObject = new TestClass2();
    Method testMethod = TestClass2.class.getMethod("test1");

    listener.beforeTestSetUp(testObject, testMethod);
    EasyMock.expectLastCall().andThrow(new NullPointerException());
    
    EasyMockUnitils.replay();
    new BeforeTestSetUpStatement(testObject, testMethod, listener, statement).evaluate();
    
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:13,代码来源:BeforeTestSetUpStatementTest.java


示例19: testEvaluateExceptionOnStatement

import org.easymock.classextension.EasyMock; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testEvaluateExceptionOnStatement() throws Throwable {
    TestClass2 testObject = new TestClass2();
    Method testMethod = TestClass2.class.getMethod("test1");

    listener.beforeTestSetUp(testObject, testMethod);
    statement.evaluate();
    EasyMock.expectLastCall().andThrow(new NullPointerException());
    
    EasyMockUnitils.replay();
    new BeforeTestSetUpStatement(testObject, testMethod, listener, statement).evaluate();
    
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:14,代码来源:BeforeTestSetUpStatementTest.java


示例20: testEvaluateStatementException

import org.easymock.classextension.EasyMock; //导入依赖的package包/类
/**
 * Test method for {@link org.unitils.core.junit.AfterTestTearDownStatement#evaluate()}.
 */
@Test(expected = NullPointerException.class)
public void testEvaluateStatementException() throws Throwable {
    TestClass2 testObject = new TestClass2();
    Method testMethod = TestClass2.class.getMethod("test1");

    statement.evaluate();
    EasyMock.expectLastCall().andThrow(new NullPointerException());
    listener.afterTestTearDown(testObject, testMethod);

    EasyMockUnitils.replay();
    new AfterTestTearDownStatement(listener, statement, testObject, testMethod).evaluate();

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:17,代码来源:AfterTestTearDownStatementTest.java



注:本文中的org.easymock.classextension.EasyMock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JSONWebService类代码示例发布时间:2022-05-21
下一篇:
Java WriteFuture类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap