Java Code Examples for org.easymock.EasyMock#createMock()

The following examples show how to use org.easymock.EasyMock#createMock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCombinedBuilderParametersImpl.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a new builder provider can be registered.
 */
@Test
public void testRegisterProvider()
{
    final ConfigurationBuilderProvider provider =
            EasyMock.createMock(ConfigurationBuilderProvider.class);
    EasyMock.replay(provider);
    final String tagName = "testTag";
    final CombinedBuilderParametersImpl params = new CombinedBuilderParametersImpl();
    assertSame("Wrong result", params,
            params.registerProvider(tagName, provider));
    final Map<String, ConfigurationBuilderProvider> providers =
            params.getProviders();
    assertEquals("Wrong number of providers", 1, providers.size());
    assertSame("Wrong provider (1)", provider, providers.get(tagName));
    assertSame("Wrong provider (2)", provider,
            params.providerForTag(tagName));
}
 
Example 2
Source File: FailoverClusterInvokerTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * @throws java.lang.Exception
 */

@Before
public void setUp() throws Exception {
    
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(invokers).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    invokers.add(invoker2);
}
 
Example 3
Source File: InvokerTelnetHandlerTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() 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(null).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, "echo(\"ok\")");
    assertTrue(result.contains("ok"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 4
Source File: InvokerTelnetHandlerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() 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(null).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, "echo(\"ok\")");
    assertTrue(result.contains("ok"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 5
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiplexGetId() throws Exception {
    destination = setUpDestination();

    final String id = "ID3";
    EndpointReferenceType refWithId = destination.getAddressWithId(id);

    Map<String, Object> context = new HashMap<>();
    assertNull("fails with no context", destination.getId(context));

    AddressingProperties maps = EasyMock.createMock(AddressingProperties.class);
    maps.getToEndpointReference();
    EasyMock.expectLastCall().andReturn(refWithId);
    EasyMock.replay(maps);
    context.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);
    String result = destination.getId(context);
    assertNotNull(result);
    assertEquals("match our id", result, id);
}
 
Example 6
Source File: TestParameters.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a parameters object for an XML configuration can be
 * created.
 */
@Test
public void testXml()
{
    final ExpressionEngine engine = EasyMock.createMock(ExpressionEngine.class);
    final Map<String, Object> map =
            new Parameters().xml().setThrowExceptionOnMissing(true)
                    .setFileName("test.xml").setValidating(true)
                    .setExpressionEngine(engine).setListDelimiterHandler(listHandler)
                    .setSchemaValidation(true).getParameters();
    checkBasicProperties(map);
    final FileBasedBuilderParametersImpl fbp =
            FileBasedBuilderParametersImpl.fromParameters(map);
    assertEquals("Wrong file name", "test.xml", fbp.getFileHandler()
            .getFileName());
    assertEquals("Wrong validation flag", Boolean.TRUE,
            map.get("validating"));
    assertEquals("Wrong schema flag", Boolean.TRUE,
            map.get("schemaValidation"));
    assertEquals("Wrong expression engine", engine,
            map.get("expressionEngine"));
}
 
Example 7
Source File: BasicThreadFactoryTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests whether the exception handler is set if one is provided.
 */
@Test
public void testNewThreadExHandler() {
    ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
    Runnable r = EasyMock.createMock(Runnable.class);
    Thread.UncaughtExceptionHandler handler = EasyMock
            .createMock(Thread.UncaughtExceptionHandler.class);
    Thread t = new Thread();
    EasyMock.expect(wrapped.newThread(r)).andReturn(t);
    EasyMock.replay(wrapped, r, handler);
    BasicThreadFactory factory = builder.wrappedFactory(wrapped)
            .uncaughtExceptionHandler(handler).build();
    assertSame("Wrong thread", t, factory.newThread(r));
    assertEquals("Wrong exception handler", handler, t
            .getUncaughtExceptionHandler());
    EasyMock.verify(wrapped, r, handler);
}
 
Example 8
Source File: ODataJPAResponseBuilderTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private EdmEntityContainer getLocalEdmEntityContainer() {
  EdmEntityContainer edmEntityContainer = EasyMock
      .createMock(EdmEntityContainer.class);
  EasyMock.expect(edmEntityContainer.isDefaultEntityContainer())
      .andStubReturn(true);
  try {
    EasyMock.expect(edmEntityContainer.getName()).andStubReturn(
        "salesorderprocessingContainer");
  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
        + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }

  EasyMock.replay(edmEntityContainer);
  return edmEntityContainer;
}
 
Example 9
Source File: NodeStructureHelper.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a mock for a resolver.
 *
 * @return the resolver mock
 */
public static NodeKeyResolver<ImmutableNode> createResolverMock()
{
    @SuppressWarnings("unchecked")
    final
    NodeKeyResolver<ImmutableNode> mock =
            EasyMock.createMock(NodeKeyResolver.class);
    return mock;
}
 
Example 10
Source File: MongoClientClosedExceptionTest.java    From mongodb-async-driver with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link MongoClientClosedException#MongoClientClosedException(Message)}.
 */
@Test
public void testMongoClientClosedExceptionMessage() {
    final Message message = EasyMock.createMock(Message.class);

    final MongoClientClosedException exception = new MongoClientClosedException(
            message);
    assertNull(exception.getCause());
    assertEquals("MongoClient has been closed.", exception.getMessage());
    assertSame(message, exception.getSentMessage());
}
 
Example 11
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test(expectedExceptions = RuntimeException.class,
    expectedExceptionsMessageRegExp = SceneAccessLayer.FAILED_TO_WRITE_SCENE_TO_THE_FILE)
public void testRecordWriteFailure()
    throws IOException {
  Scene scene = EasyMock.createMock(Scene.class);
  EasyMock.expect(scene.isSequential()).andReturn(false).anyTimes();
  RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
  RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);
  RecordedHttpResponse incomingHttpResponse = EasyMock.createStrictMock(RecordedHttpResponse.class);

  ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
  recordedHttpExchangeArrayList.add(recordedHttpExchange1);
  recordedHttpExchangeArrayList.add(recordedHttpExchange2);
  EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList).times(3);
  SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);

  MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(true);
  sceneWriter.writeScene(scene);
  EasyMock.expectLastCall().andThrow(new IOException());

  EasyMock.replay(scene, sceneWriter, recordedHttpExchange1, recordedHttpExchange2, matchRule);
  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);
  sceneAccessLayer.record(incomingHttpRequest, incomingHttpResponse);
  sceneAccessLayer.flush();
  EasyMock.verify(scene, sceneWriter, recordedHttpExchange1, recordedHttpExchange2, matchRule);
}
 
Example 12
Source File: HeartbeatManagerImplTest.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void init() {
  mockJmsSender = EasyMock.createMock(JmsSender.class);
  ClusterCache clusterCache = EasyMock.createControl().createMock(ClusterCache.class);
  heartbeatManagerImpl = new HeartbeatManagerImpl(mockJmsSender, clusterCache);
  heartbeatManagerImpl.setHeartbeatInterval(INTERVAL);
}
 
Example 13
Source File: ViewEngineBaseTest.java    From ozark with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveViewCustomFolder() {
	ViewEngineContext ctx = EasyMock.createMock(ViewEngineContext.class);
	Configuration config = EasyMock.createMock(Configuration.class);
	expect(config.getProperty(eq(ViewEngine.VIEW_FOLDER))).andReturn("/somewhere/else");
	expect(ctx.getConfiguration()).andReturn(config);
	expect(ctx.getView()).andReturn("index.jsp");
	replay(ctx, config);
	assertThat(viewEngineBase.resolveView(ctx), is("/somewhere/else/index.jsp"));
	verify(ctx, config);
}
 
Example 14
Source File: JPQLJoinSelectSingleStatementBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public void setUp(final List<JPAJoinClause> joinClauseList) throws Exception {
  context = EasyMock.createMock(JPQLJoinSelectSingleContextView.class);
  EasyMock.expect(context.getJPAEntityAlias()).andStubReturn("gt1");
  EasyMock.expect(context.getJPAEntityName()).andStubReturn("SOHeader");
  EasyMock.expect(context.getType()).andStubReturn(JPQLContextType.SELECT);
  EasyMock.expect(context.getKeyPredicates()).andStubReturn(createKeyPredicates());
  EasyMock.expect(context.getSelectExpression()).andStubReturn("gt1");
  EasyMock.expect(context.getJPAJoinClauses()).andStubReturn(joinClauseList);
  context.setJPQLStatement("SELECT gt1 FROM SOHeader soh JOIN "
      + "soh.soItem soi JOIN soi.material mat WHERE soh.soId = 1 AND " +
          "soi.shId = soh.soId AND mat.id = 'abc'");
  EasyMock.replay(context);
}
 
Example 15
Source File: OspfNbrImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests processLsUpdate() method.
 */
@Test
public void testProcessLsUpdate() throws Exception {
    LsUpdate ospfMessage = new LsUpdate();
    ospfMessage.setSourceIp(Ip4Address.valueOf("10.10.10.10"));
    ospfMessage.addLsa(new RouterLsa());
    ospfMessage.addLsa(new NetworkLsa());
    channel = EasyMock.createMock(Channel.class);
    ospfNbr.setState(OspfNeighborState.EXCHANGE);
    ospfNbr.processLsUpdate(ospfMessage, channel);
    assertThat(ospfNbr, is(notNullValue()));
}
 
Example 16
Source File: OspfInterfaceImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests electRouter() method.
 */
@Test
public void testElectRouter() throws Exception {
    ospfInterface.setOspfArea(ospfArea);
    ospfInterface.setDr(Ip4Address.valueOf("3.3.3.3"));
    ospfInterface.setBdr(Ip4Address.valueOf("3.3.3.3"));
    ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
    ChannelConfig channelConfig = EasyMock.createMock(ChannelConfig.class);
    EasyMock.expect(channelConfig.getBufferFactory()).andReturn(new HeapChannelBufferFactory());
    Channel channel = EasyMock.createMock(Channel.class);
    ospfInterface.electRouter(channel);
    assertThat(ospfInterface.dr(), is(notNullValue()));
}
 
Example 17
Source File: ImageElementSelectorTest.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param selector
 * @param doc 
 */
private void initMockContext(String selector, Document doc) {
    ssp = EasyMock.createMock(SSP.class);
    EasyMock.expect(ssp.getDOM()).andReturn("").once();
    EasyMock.replay(ssp);
    sspHandler = EasyMock.createMock(SSPHandler.class);
    EasyMock.expect(sspHandler.beginCssLikeSelection()).andReturn(sspHandler).once();
    EasyMock.expect(sspHandler.domCssLikeSelectNodeSet(selector)).andReturn(sspHandler).once();
    EasyMock.expect(sspHandler.getSelectedElements()).andReturn(doc.select(selector)).once();
    EasyMock.expect(sspHandler.getSSP()).andReturn(ssp);
    EasyMock.replay(sspHandler);
}
 
Example 18
Source File: SupervisionNotifierTest.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test registration.
 */
@Test
public void testRegisterListener() {
  SupervisionListener supervisionListener = EasyMock.createMock(SupervisionListener.class);
  supervisionNotifier.registerAsListener(supervisionListener);
}
 
Example 19
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private Query getQueryForSelectCount() {
  Query query = EasyMock.createMock(Query.class);
  EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
  EasyMock.replay(query);
  return query;
}
 
Example 20
Source File: ODataJPAContextMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private static Metamodel mockMetaModel() {
  Metamodel metaModel = EasyMock.createMock(Metamodel.class);
  EasyMock.replay(metaModel);
  return metaModel;
}