当前位置: 首页>>代码示例>>Java>>正文


Java EasyMock类代码示例

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


EasyMock类属于org.easymock包,在下文中一共展示了EasyMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAdjOk

import org.easymock.EasyMock; //导入依赖的package包/类
/**
 * Tests adjOk() method.
 */
@Test
public void testAdjOk() throws Exception {
    channel = EasyMock.createMock(Channel.class);
    ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
    ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
    ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
                               Ip4Address.valueOf("2.2.2.2"), 2,
                               topologyForDeviceAndLink);
    ospfNbr1.setState(OspfNeighborState.TWOWAY);
    ospfNbr1.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
    ospfNbr1.adjOk(channel);
    assertThat(ospfNbr1, is(notNullValue()));

    ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
    ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
                               Ip4Address.valueOf("2.2.2.2"), 2,
                               topologyForDeviceAndLink);
    channel = null;
    channel = EasyMock.createMock(Channel.class);
    ospfNbr1.adjOk(channel);
    assertThat(ospfNbr1, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:OspfNbrImplTest.java

示例2: testUnnamedSection

import org.easymock.EasyMock; //导入依赖的package包/类
@Test public void testUnnamedSection() throws Exception
{
    IniParser parser = new IniParser();
    IniHandler handler = EasyMock.createMock(IniHandler.class);

    handler.startIni();
    handler.startSection(EMPTY);
    handler.handleOption(OPTION, VALUE);
    handler.endSection();
    handler.endIni();
    EasyMock.replay(handler);
    Config cfg = new Config();

    cfg.setUnnamedSection(true);
    parser.setConfig(cfg);
    parser.parse(new StringReader(CFG_UNNAMED), handler);
    EasyMock.verify(handler);
}
 
开发者ID:JetBrains,项目名称:intellij-deps-ini4j,代码行数:19,代码来源:IniParserTest.java

示例3: 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:yunhaibin,项目名称:dubbox-hystrix,代码行数:22,代码来源:ContextFilterTest.java

示例4: testaa

import org.easymock.EasyMock; //导入依赖的package包/类
@Test
public void testaa() throws Exception {
    Account tiliMock = createMock(Account.class);

    expectNew(Account.class, EasyMock.anyString(), EasyMock.eq(100.0)).andReturn(tiliMock);

    tiliMock.deposit(20.0);
    replay(tiliMock, Account.class);

    try {
        Accounts.main(new String[0]);
        verify(tiliMock, Account.class);

    } catch (Throwable t) {
        String virhe = t.getMessage();
        if (virhe.contains("deposit")) {
            fail("create an account and do a deposit of 20");
        } else if (virhe.contains("constructor")) {
            fail("remember to create account with initial balance of 100.0, "
                    + "the value should be in the constructor parameter");
        }
        fail("Something unexpected happened:\n" + virhe);
    }
}
 
开发者ID:gengwg,项目名称:java_mooc_fi,代码行数:25,代码来源:AccountsTest.java

示例5: createOspfInterface1

import org.easymock.EasyMock; //导入依赖的package包/类
/**
 * Utility for test method.
 */
private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException {
    ospfInterface = new OspfInterfaceImpl();
    OspfAreaImpl ospfArea = new OspfAreaImpl();
    OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
            OspfInterfaceChannelHandler.class);
    ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
                              Ip4Address.valueOf("1.1.1.1"), 2,
                              topologyForDeviceAndLink);
    ospfNbr.setState(OspfNeighborState.FULL);
    ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
    ospfInterface = new OspfInterfaceImpl();
    ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
    ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
    ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
    ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
    ospfInterface.setHelloIntervalTime(20);
    ospfInterface.setInterfaceType(2);
    ospfInterface.setReTransmitInterval(2000);
    ospfInterface.setMtu(6500);
    ospfInterface.setRouterDeadIntervalTime(1000);
    ospfInterface.setRouterPriority(1);
    ospfInterface.setInterfaceType(1);
    ospfInterface.addNeighbouringRouter(ospfNbr);
    return ospfInterface;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:OspfInterfaceImplTest.java

示例6: expectOffsetFlush

import org.easymock.EasyMock; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void expectOffsetFlush(boolean succeed) throws Exception {
    EasyMock.expect(offsetWriter.beginFlush()).andReturn(true);
    Future<Void> flushFuture = PowerMock.createMock(Future.class);
    EasyMock.expect(offsetWriter.doFlush(EasyMock.anyObject(Callback.class))).andReturn(flushFuture);
    // Should throw for failure
    IExpectationSetters<Void> futureGetExpect = EasyMock.expect(
            flushFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class)));
    if (succeed) {
        sourceTask.commit();
        EasyMock.expectLastCall();
        futureGetExpect.andReturn(null);
    } else {
        futureGetExpect.andThrow(new TimeoutException());
        offsetWriter.cancelFlush();
        PowerMock.expectLastCall();
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:WorkerSourceTaskTest.java

示例7: testInvalidSHA256Password

import org.easymock.EasyMock; //导入依赖的package包/类
@Test
public void testInvalidSHA256Password() throws Exception {
    final UserPasswordDao userPasswordDao = EasyMock.createMock(UserPasswordDao.class);
    EasyMock.expect(userPasswordDao.getPasswordHash("student"))
            .andReturn("(SHA256)KwAQC001SoPq/CjHMLSz2o0aAqx7WrKeRFgWOeM2GEyLXGZd+1/XkA==");

    final PersonDirAuthenticationHandler authenticationHandler =
            new PersonDirAuthenticationHandler();
    authenticationHandler.setUserPasswordDao(userPasswordDao);

    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials();
    credentials.setUsername("student");
    credentials.setPassword("student");

    EasyMock.replay(userPasswordDao);

    final boolean auth =
            authenticationHandler.authenticateUsernamePasswordInternal(credentials);

    EasyMock.verify(userPasswordDao);

    assertFalse(auth);
}
 
开发者ID:Jasig,项目名称:uPortal-start,代码行数:24,代码来源:PersonDirAuthenticationHandlerTest.java

示例8: testNegotiationDone

import org.easymock.EasyMock; //导入依赖的package包/类
/**
 * Tests negotiationDone() method.
 */
@Test
public void testNegotiationDone() throws Exception {

    ospfLsaList = new ArrayList();
    RouterLsa routerLsa = new RouterLsa();
    routerLsa.setLsType(OspfLsaType.ROUTER.value());
    ospfLsaList.add(routerLsa);
    DdPacket ddPacket = new DdPacket();
    ddPacket.setIsOpaqueCapable(true);
    ospfMessage = ddPacket;
    ospfNbr.setState(OspfNeighborState.EXSTART);
    ospfNbr.setIsOpaqueCapable(true);
    channel = null;
    channel = EasyMock.createMock(Channel.class);
    ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel);
    channel1 = EasyMock.createMock(Channel.class);
    ospfNbr.negotiationDone(ospfMessage, false, ospfLsaList, channel1);
    assertThat(ospfNbr, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:OspfNbrImplTest.java

示例9: testNullPassword

import org.easymock.EasyMock; //导入依赖的package包/类
@Test
public void testNullPassword() throws Exception {
    final UserPasswordDao userPasswordDao = EasyMock.createMock(UserPasswordDao.class);
    EasyMock.expect(userPasswordDao.getPasswordHash("admin")).andReturn(null);

    final PersonDirAuthenticationHandler authenticationHandler =
            new PersonDirAuthenticationHandler();
    authenticationHandler.setUserPasswordDao(userPasswordDao);

    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials();
    credentials.setUsername("admin");
    credentials.setPassword("admin");

    EasyMock.replay(userPasswordDao);

    final boolean auth =
            authenticationHandler.authenticateUsernamePasswordInternal(credentials);

    EasyMock.verify(userPasswordDao);

    assertFalse(auth);
}
 
开发者ID:Jasig,项目名称:uPortal-start,代码行数:23,代码来源:PersonDirAuthenticationHandlerTest.java

示例10: testEcho

import org.easymock.EasyMock; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testEcho() {
    Invocation invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$echo").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<DemoService> 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 = echoFilter.invoke(invoker, invocation);
    assertEquals("hello", filterResult.getValue());
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:22,代码来源:EchoFilterTest.java

示例11: testListDetail

import org.easymock.EasyMock; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
    int port = NetUtils.getAvailablePort();
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "-l");
    assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
    EasyMock.reset(mockChannel);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:17,代码来源:ListTelnetHandlerTest.java

示例12: expectPollInitialAssignment

import org.easymock.EasyMock; //导入依赖的package包/类
private void expectPollInitialAssignment() throws Exception {
    final List<TopicPartition> partitions = Arrays.asList(TOPIC_PARTITION, TOPIC_PARTITION2, TOPIC_PARTITION3);

    sinkTask.open(partitions);
    EasyMock.expectLastCall();

    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(new IAnswer<ConsumerRecords<byte[], byte[]>>() {
        @Override
        public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
            rebalanceListener.getValue().onPartitionsAssigned(partitions);
            return ConsumerRecords.empty();
        }
    });
    EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION3)).andReturn(FIRST_OFFSET);

    sinkTask.put(Collections.<SinkRecord>emptyList());
    EasyMock.expectLastCall();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:WorkerSinkTaskThreadedTest.java

示例13: testProcessHelloMessage

import org.easymock.EasyMock; //导入依赖的package包/类
/**
 * Tests processHelloMessage() method.
 */
@Test
public void testProcessHelloMessage() throws Exception {
    ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
    ospfInterface.setInterfaceType(1);
    ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
    ospfInterface.setHelloIntervalTime(10);
    ospfInterface.setRouterDeadIntervalTime(10);
    ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
    channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
    OspfMessage message;
    helloPacket = new HelloPacket();
    helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
    helloPacket.setOspfVer(2);
    helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
    helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
    helloPacket.setHelloInterval(10);
    helloPacket.setRouterDeadInterval(10);
    helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
    helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
    helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111"));
    message = helloPacket;
    ospfInterface.processHelloMessage(message, channelHandlerContext);
    assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:OspfInterfaceImplTest.java

示例14: testInvokeDefaultSService

import org.easymock.EasyMock; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
    EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
    EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
    assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:InvokerTelnetHandlerTest.java

示例15: expectConsumerPoll

import org.easymock.EasyMock; //导入依赖的package包/类
private void expectConsumerPoll(final int numMessages, final long timestamp, final TimestampType timestampType) {
    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
            new IAnswer<ConsumerRecords<byte[], byte[]>>() {
                @Override
                public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
                    List<ConsumerRecord<byte[], byte[]>> records = new ArrayList<>();
                    for (int i = 0; i < numMessages; i++)
                        records.add(new ConsumerRecord<>(TOPIC, PARTITION, FIRST_OFFSET + recordsReturned + i, timestamp, timestampType, 0L, 0, 0, RAW_KEY, RAW_VALUE));
                    recordsReturned += numMessages;
                    return new ConsumerRecords<>(
                            numMessages > 0 ?
                                    Collections.singletonMap(new TopicPartition(TOPIC, PARTITION), records) :
                                    Collections.<TopicPartition, List<ConsumerRecord<byte[], byte[]>>>emptyMap()
                    );
                }
            });
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:WorkerSinkTaskTest.java


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