當前位置: 首頁>>代碼示例>>Java>>正文


Java EasyMock.createMock方法代碼示例

本文整理匯總了Java中org.easymock.EasyMock.createMock方法的典型用法代碼示例。如果您正苦於以下問題:Java EasyMock.createMock方法的具體用法?Java EasyMock.createMock怎麽用?Java EasyMock.createMock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.easymock.EasyMock的用法示例。


在下文中一共展示了EasyMock.createMock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void test() {
  KafkaCruiseControl mockKCC = EasyMock.createMock(KafkaCruiseControl.class);
  KafkaCruiseControlState kccState = getState(_numReadyGoals, _totalGoals, _numValidWindows);
  EasyMock.expect(mockKCC.state()).andReturn(kccState).anyTimes();
  EasyMock.replay(mockKCC);
  
  KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(mockKCC);
  KafkaCruiseControlServlet.GoalsAndRequirements goalsAndRequirements = 
      servlet.getGoalsAndRequirements(Collections.emptyList(),
                                      _dataFrom,
                                      false);
  
  assertEquals(new HashSet<>(goalsAndRequirements.goals()), new HashSet<>(_expectedGoalsToUse));
  if (_expectedRequirements != null) {
    assertEquals(_expectedRequirements.minRequiredNumSnapshotWindows(), 
                 goalsAndRequirements.requirements().minRequiredNumSnapshotWindows());
    assertEquals(_expectedRequirements.minMonitoredPartitionsPercentage(), 
                 goalsAndRequirements.requirements().minMonitoredPartitionsPercentage(), 0.0);
    assertEquals(_expectedRequirements.includeAllTopics(), 
                 goalsAndRequirements.requirements().includeAllTopics());
  } else {
    assertNull("The requirement should be null", goalsAndRequirements.requirements());
  }
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:26,代碼來源:KafkaCruiseControlServletDataFromTest.java

示例2: testInvokerGeneric

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testInvokerGeneric() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:20,代碼來源:CompatibleFilterFilterTest.java

示例3: testRpcException

import org.easymock.EasyMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:24,代碼來源:ExceptionFilterTest.java

示例4: testSetContext

import org.easymock.EasyMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testSetContext() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:22,代碼來源:ContextFilterTest.java

示例5: testNoInvoke

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(DemoService.class).anyTimes();
    
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    resetInvokerToNoException();
    
    FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
    LogUtil.start();
    invoker.invoke(invocation);
    assertTrue(LogUtil.findMessage("No provider") > 0);
    LogUtil.stop();
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:20,代碼來源:FailSafeClusterInvokerTest.java

示例6: setupMock

import org.easymock.EasyMock; //導入方法依賴的package包/類
private ClientFactory setupMock() throws Exception {

        ArrayList<CMODataTransport> transports = new ArrayList<>();
        transports.add(new CMODataTransport("L21K900026", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K900028", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K900029", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K90002A", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K90002B", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K90002C", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K90002D", false, "Description", "Owner"));
        transports.add(new CMODataTransport("L21K90002E", true, "Description", "Owner"));

        CMODataClient clientMock = createMock(CMODataClient.class);
        expect(clientMock.getChangeTransports(capture(changeId))).andReturn(transports);

        ClientFactory factoryMock = EasyMock.createMock(ClientFactory.class);
        expect(factoryMock
                .newClient(capture(host),
                        capture(user),
                        capture(password))).andReturn(clientMock);
        clientMock.close(); expectLastCall();

        replay(clientMock, factoryMock);

        return factoryMock;
    }
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:27,代碼來源:GetChangeTransportsTest.java

示例7: testNoInvoke

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:22,代碼來源:FailoverClusterInvokerTest.java

示例8: testCloseAvailablecheck

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testCloseAvailablecheck() {
    LoadBalance lb = EasyMock.createMock(LoadBalance.class);
    EasyMock.expect(lb.select(invokers, url, invocation)).andReturn(invoker1);
    EasyMock.replay(lb);
    initlistsize5();

    Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
    Assert.assertEquals(false, sinvoker.isAvailable());
    Assert.assertEquals(invoker1, sinvoker);

}
 
開發者ID:l1325169021,項目名稱:github-test,代碼行數:13,代碼來源:AbstractClusterInvokerTest.java

示例9: testChangeLogLevel

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testChangeLogLevel() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.replay(mockChannel);
    String result = log.telnet(mockChannel, "error");
    assertTrue(result.contains("\r\nCURRENT LOG LEVEL:ERROR"));
    String result2 = log.telnet(mockChannel, "warn");
    assertTrue(result2.contains("\r\nCURRENT LOG LEVEL:WARN"));
    EasyMock.reset(mockChannel);
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:11,代碼來源:LogTelnetHandlerTest.java

示例10: testMessageError

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testMessageError() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = count.telnet(mockChannel, "test");
    assertEquals("Unsupported parameter test for pwd.", result);
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:9,代碼來源:CurrentTelnetHandlerTest.java

示例11: setUp

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    isisHeader = new IsisHeader();
    isisHeader.setIsisPduType(IsisPduType.L1PSNP.value());
    psnp = new Psnp(isisHeader);
    tlvHeader = new TlvHeader();
    channelBuffer = EasyMock.createMock(ChannelBuffer.class);
    isisTlv = new AdjacencyStateTlv(tlvHeader);

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:11,代碼來源:PsnpTest.java

示例12: testCloseAvailablecheck

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testCloseAvailablecheck(){
    LoadBalance lb = EasyMock.createMock(LoadBalance.class);
    EasyMock.expect(lb.select(invokers, url, invocation)).andReturn(invoker1);
    EasyMock.replay(lb);
    initlistsize5();
    
    Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
    Assert.assertEquals(false,sinvoker.isAvailable());
    Assert.assertEquals(invoker1,sinvoker);
    
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:13,代碼來源:AbstractClusterInvokerTest.java

示例13: testChannelConnected

import org.easymock.EasyMock; //導入方法依賴的package包/類
/**
 * Tests channelConnected() method.
 */
@Test(expected = Exception.class)
public void testChannelConnected() throws Exception {
    channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
    channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
    ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:10,代碼來源:OspfInterfaceChannelHandlerTest.java

示例14: setUp

import org.easymock.EasyMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    tlvHeader = new TlvHeader();
    tlvHeader.setTlvLength(tlv.length);
    hostNameTlv = new HostNameTlv(tlvHeader);
    channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:8,代碼來源:HostNameTlvTest.java

示例15: testTruncateIfSizeIsDifferentToTargetSize

import org.easymock.EasyMock; //導入方法依賴的package包/類
/**
 * see #testTruncateNotCalledIfSizeIsSameAsTargetSize
 */
@Test
public void testTruncateIfSizeIsDifferentToTargetSize() throws IOException {
    FileChannel channelMock = EasyMock.createMock(FileChannel.class);

    EasyMock.expect(channelMock.size()).andReturn(42L).atLeastOnce();
    EasyMock.expect(channelMock.position(42L)).andReturn(null).once();
    EasyMock.expect(channelMock.truncate(23L)).andReturn(null).once();
    EasyMock.replay(channelMock);

    FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
    fileRecords.truncateTo(23);

    EasyMock.verify(channelMock);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,代碼來源:FileRecordsTest.java


注:本文中的org.easymock.EasyMock.createMock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。