org.easymock.EasyMock.createMock()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.easymock.EasyMock.createMock()方法的一些代码示例,展示了EasyMock.createMock()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.createMock()方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:createMock

EasyMock.createMock介绍

[英]Creates a mock object that implements the given interface, order checking is disabled by default.
[中]创建实现给定接口的模拟对象,默认情况下禁用顺序检查。

代码示例

代码示例来源:origin: apache/incubator-druid

@Test
public void testGetEmitter()
{
 ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class);
 EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes();
 Injector injector = EasyMock.createMock(Injector.class);
 EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter);
 EasyMock.replay(config, injector);
 Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector);
 composingEmitter.start();
 EasyMock.verify(config, emitter, injector);
}

代码示例来源:origin: apache/incubator-druid

@Test(expected = IllegalStateException.class)
public void testAddExceptionWhenClosed()
{
 lookupReferencesManager.add("test", EasyMock.createMock(LookupExtractorFactoryContainer.class));
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testEmit()
{
 Event e = EasyMock.createMock(Event.class);
 for (Emitter emitter : childEmitters) {
  emitter.emit(e);
  EasyMock.replay(emitter);
 }
 composingEmitter.emit(e);
}

代码示例来源:origin: apache/incubator-druid

private static LoadQueuePeon createLoadingPeon(List<DataSegment> segments)
 {
  final Set<DataSegment> segs = ImmutableSet.copyOf(segments);
  final long loadingSize = segs.stream().mapToLong(DataSegment::getSize).sum();

  final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
  EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(segs).anyTimes();
  EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
  EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(loadingSize).anyTimes();
  EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(segs.size()).anyTimes();

  return mockPeon;
 }
}

代码示例来源:origin: apache/incubator-druid

@Before
public void setUp()
{
 resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class);
 EasyMock.replay(resourceFactory);
 pool = new ResourcePool<String, String>(
   resourceFactory,
   new ResourcePoolConfig(2, TimeUnit.MINUTES.toMillis(4))
 );
 EasyMock.verify(resourceFactory);
 EasyMock.reset(resourceFactory);
}

代码示例来源:origin: apache/incubator-druid

@Before
public void setup()
{
 emitter = EasyMock.createMock(Emitter.class);
 emitter.start();
 EasyMock.replay(emitter);
}

代码示例来源:origin: apache/incubator-druid

private Task createMockTask(String type)
{
 Task mock = EasyMock.createMock(Task.class);
 EasyMock.expect(mock.getType()).andReturn(type).anyTimes();
 EasyMock.replay(mock);
 return mock;
}

代码示例来源:origin: apache/incubator-druid

@Before
public void setUp()
{
 tierSelectorStrategy = EasyMock.createMock(TierSelectorStrategy.class);
 expect(tierSelectorStrategy.getComparator()).andReturn(Integer::compare).anyTimes();
}

代码示例来源:origin: apache/incubator-druid

@Before
public void setUp()
{
 ServiceEmitter emitter = EasyMock.createMock(ServiceEmitter.class);
 EmittingLogger.registerEmitter(emitter);
 EasyMock.replay(emitter);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests whether the thread name is not modified if no naming pattern is
 * set.
 */
@Test
public void testNewThreadNoNamingPattern() {
  final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
  final Runnable r = EasyMock.createMock(Runnable.class);
  final String name = "unchangedThreadName";
  final Thread t = new Thread(name);
  EasyMock.expect(wrapped.newThread(r)).andReturn(t);
  EasyMock.replay(wrapped, r);
  final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
  assertSame("Wrong thread", t, factory.newThread(r));
  assertEquals("Name was changed", name, t.getName());
  EasyMock.verify(wrapped, r);
}

代码示例来源:origin: apache/incubator-druid

private static ShardSpec shardSpec(String dimension, boolean contained)
 {
  ShardSpec shard = EasyMock.createMock(ShardSpec.class);
  EasyMock.expect(shard.getDomainDimensions())
      .andReturn(ImmutableList.of(dimension))
      .anyTimes();
  EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject()))
      .andReturn(contained)
      .anyTimes();
  return shard;
 }
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests whether the original priority is not changed if no priority is
 * specified.
 */
@Test
public void testNewThreadNoPriority() {
  final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
  final Runnable r = EasyMock.createMock(Runnable.class);
  final int orgPriority = Thread.NORM_PRIORITY + 1;
  final Thread t = new Thread();
  t.setPriority(orgPriority);
  EasyMock.expect(wrapped.newThread(r)).andReturn(t);
  EasyMock.replay(wrapped, r);
  final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
  assertSame("Wrong thread", t, factory.newThread(r));
  assertEquals("Wrong priority", orgPriority, t.getPriority());
  EasyMock.verify(wrapped, r);
}

代码示例来源:origin: apache/incubator-druid

private static LoadQueuePeon createEmptyPeon()
{
 final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
 EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes();
 EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
 EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes();
 EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes();
 return mockPeon;
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testRewriteURI()
{
 DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class);
 EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port");
 HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
 EasyMock.expect(request.getQueryString()).andReturn("param1=test&param2=test2").anyTimes();
 // %3A is a colon; test to make sure urlencoded paths work right.
 EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes();
 EasyMock.replay(druidLeaderClient, request);
 URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request));
 Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test&param2=test2", uri.toString());
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests a successful initializeUnchecked() operation.
 *
 * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
 */
@Test
public void testInitializeUnchecked() throws ConcurrentException {
  @SuppressWarnings("unchecked")
  final
  ConcurrentInitializer<Object> init = EasyMock
      .createMock(ConcurrentInitializer.class);
  final Object result = new Object();
  EasyMock.expect(init.get()).andReturn(result);
  EasyMock.replay(init);
  assertSame("Wrong result object", result, ConcurrentUtils
      .initializeUnchecked(init));
  EasyMock.verify(init);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests a successful initialize() operation.
 *
 * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
 */
@Test
public void testInitialize() throws ConcurrentException {
  @SuppressWarnings("unchecked")
  final
  ConcurrentInitializer<Object> init = EasyMock
      .createMock(ConcurrentInitializer.class);
  final Object result = new Object();
  EasyMock.expect(init.get()).andReturn(result);
  EasyMock.replay(init);
  assertSame("Wrong result object", result, ConcurrentUtils
      .initialize(init));
  EasyMock.verify(init);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests multiple invocations of the shutdown() method.
 *
 * @throws java.lang.InterruptedException so we don't have to catch it
 */
@Test
public void testShutdownMultipleTimes() throws InterruptedException {
  final ScheduledExecutorService service = EasyMock
      .createMock(ScheduledExecutorService.class);
  final ScheduledFuture<?> future = EasyMock.createMock(ScheduledFuture.class);
  prepareStartTimer(service, future);
  EasyMock.expect(Boolean.valueOf(future.cancel(false))).andReturn(Boolean.TRUE);
  EasyMock.replay(service, future);
  final TimedSemaphoreTestImpl semaphore = new TimedSemaphoreTestImpl(service,
      PERIOD, UNIT, LIMIT);
  semaphore.acquire();
  for (int i = 0; i < 10; i++) {
    semaphore.shutdown();
  }
  EasyMock.verify(service, future);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests whether the priority is set on newly created threads.
 */
@Test
public void testNewThreadPriority() {
  final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
  final Runnable r = EasyMock.createMock(Runnable.class);
  final Thread t = new Thread();
  EasyMock.expect(wrapped.newThread(r)).andReturn(t);
  EasyMock.replay(wrapped, r);
  final int priority = Thread.NORM_PRIORITY + 1;
  final BasicThreadFactory factory = builder.wrappedFactory(wrapped).priority(
      priority).build();
  assertSame("Wrong thread", t, factory.newThread(r));
  assertEquals("Wrong priority", priority, t.getPriority());
  EasyMock.verify(wrapped, r);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
   * Tests whether the original exception handler is not touched if none is
   * specified.
   */
  @Test
  public void testNewThreadNoExHandler() {
    final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
    final Runnable r = EasyMock.createMock(Runnable.class);
    final Thread.UncaughtExceptionHandler handler = EasyMock
        .createMock(Thread.UncaughtExceptionHandler.class);
    final Thread t = new Thread();
    t.setUncaughtExceptionHandler(handler);
    EasyMock.expect(wrapped.newThread(r)).andReturn(t);
    EasyMock.replay(wrapped, r, handler);
    final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
    assertSame("Wrong thread", t, factory.newThread(r));
    assertEquals("Wrong exception handler", handler, t
        .getUncaughtExceptionHandler());
    EasyMock.verify(wrapped, r, handler);
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests createIfAbsent() if a null map is passed in.
 *
 * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
 */
@Test
public void testCreateIfAbsentNullMap() throws ConcurrentException {
  @SuppressWarnings("unchecked")
  final
  ConcurrentInitializer<Integer> init = EasyMock
      .createMock(ConcurrentInitializer.class);
  EasyMock.replay(init);
  assertNull("Wrong result",
      ConcurrentUtils.createIfAbsent(null, "test", init));
  EasyMock.verify(init);
}

相关文章