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

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

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

EasyMock.anyObject介绍

[英]Expects any Object argument. For details, see the EasyMock documentation.
[中]需要任何对象参数。有关详细信息,请参阅EasyMock文档。

代码示例

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

private void mockCoordinator(DruidCoordinator coordinator)
{
 coordinator.moveSegment(
   EasyMock.anyObject(),
   EasyMock.anyObject(),
   EasyMock.anyObject(),
   EasyMock.anyObject()
 );
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(coordinator);
}

代码示例来源: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

/**
 * Prepares an executor service mock to expect the start of the timer.
 *
 * @param service the mock
 * @param future the future
 */
private void prepareStartTimer(final ScheduledExecutorService service,
    final ScheduledFuture<?> future) {
  service.scheduleAtFixedRate((Runnable) EasyMock.anyObject(), EasyMock
      .eq(PERIOD), EasyMock.eq(PERIOD), EasyMock.eq(UNIT));
  EasyMock.expectLastCall().andReturn(future);
}

代码示例来源:origin: apache/shiro

@Test
public void testHearDestroyable() throws Exception {
  TypeEncounter encounter = createMock(TypeEncounter.class);
  encounter.register(anyObject(DestroyableInjectionListener.class));
  replay(encounter);
  LifecycleTypeListener underTest = new LifecycleTypeListener(null);
  underTest.hear(TypeLiteral.get(MyDestroyable.class), encounter);
  verify(encounter);
}

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

@Test
public void testChunking()
{
 Query query = queryBuilder.intervals("2015-01-01T00:00:00.000/2015-01-11T00:00:00.000").context(ImmutableMap.of("chunkPeriod", "P1D")).build();
 executors.execute(EasyMock.anyObject(Runnable.class));
 EasyMock.expectLastCall().times(10);
 EasyMock.replay(executors);
 EasyMock.replay(toolChest);
 QueryRunner runner = decorator.decorate(baseRunner, toolChest);
 runner.run(QueryPlus.wrap(query), Collections.EMPTY_MAP);
 EasyMock.verify(executors);
}

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

private ImmutableWorkerInfo createMockWorker(int currCapacityUsed, boolean canRunTask, boolean isValidVersion)
{
 ImmutableWorkerInfo worker = EasyMock.createMock(ImmutableWorkerInfo.class);
 EasyMock.expect(worker.canRunTask(EasyMock.anyObject(Task.class))).andReturn(canRunTask).anyTimes();
 EasyMock.expect(worker.getCurrCapacityUsed()).andReturn(currCapacityUsed).anyTimes();
 EasyMock.expect(worker.isValidVersion(EasyMock.anyString())).andReturn(isValidVersion).anyTimes();
 EasyMock.replay(worker);
 return worker;
}

代码示例来源:origin: apache/shiro

@Test
public void testHearInitializable() throws Exception {
  TypeEncounter encounter = createMock(TypeEncounter.class);
  encounter.register(anyObject(InitializableInjectionListener.class));
  replay(encounter);
  LifecycleTypeListener underTest = new LifecycleTypeListener(null);
  underTest.hear(TypeLiteral.get(MyInitializable.class), encounter);
  verify(encounter);
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldWaitIfCommandSequenceNumberSpecified() throws Exception {
 // Given:
 commandQueue.ensureConsumedPast(eq(3L), anyObject());
 expectLastCall();
 replay(commandQueue);
 // When:
 testResource.streamQuery(new KsqlRequest(queryString, Collections.emptyMap(), 3L));
 // Then:
 verify(commandQueue);
}

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

@Test
public void testBadInnerInput() throws Exception
{
 final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[]{});
 final ObjectMapper mapper = EasyMock.createStrictMock(ObjectMapper.class);
 EasyMock.expect(mapper.readValue(EasyMock.<InputStream>anyObject(), EasyMock.<TypeReference<Object>>anyObject()))
     .andThrow(new IOException());
 EasyMock.replay(mapper);
 final Response response = abstractListenerHandler.handlePOSTAll(bais, mapper);
 Assert.assertEquals(400, response.getStatus());
 EasyMock.verify(mapper);
}

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

@Test
 public void testQueryRegistration()
 {
  QueryRunner baseRunner = (queryPlus, responseContext) -> null;

  QueryWatcher mock = EasyMock.createMock(QueryWatcher.class);
  mock.registerQuery(EasyMock.eq(query), EasyMock.anyObject(ListenableFuture.class));
  EasyMock.replay(mock);

  AsyncQueryRunner asyncRunner = new AsyncQueryRunner<>(baseRunner, executor, mock);

  asyncRunner.run(QueryPlus.wrap(query), Collections.EMPTY_MAP);
  EasyMock.verify(mock);
 }
}

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

@Test
 public void testChunkingOnMonths()
 {
  Query query = queryBuilder.intervals("2015-01-01T00:00:00.000/2015-02-11T00:00:00.000").context(ImmutableMap.of("chunkPeriod", "P1M")).build();

  executors.execute(EasyMock.anyObject(Runnable.class));
  EasyMock.expectLastCall().times(2);

  EasyMock.replay(executors);
  EasyMock.replay(toolChest);

  QueryRunner runner = decorator.decorate(baseRunner, toolChest);
  runner.run(QueryPlus.wrap(query), Collections.EMPTY_MAP);

  EasyMock.verify(executors);
 }
}

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

private void mockCoordinator()
{
 EasyMock.expect(coordinator.getDynamicConfigs()).andReturn(createCoordinatorDynamicConfig()).anyTimes();
 coordinator.removeSegment(EasyMock.anyObject());
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(coordinator);
}

代码示例来源:origin: apache/shiro

@Test
  public void testConstructor() {
    WebSecurityManager securityManager = createMock(WebSecurityManager.class);
    FilterChainResolver filterChainResolver = createMock(FilterChainResolver.class);
    ServletContext servletContext = createMock(ServletContext.class);

    Capture<WebGuiceEnvironment> capture = new Capture<WebGuiceEnvironment>();
    servletContext.setAttribute(eq(EnvironmentLoaderListener.ENVIRONMENT_ATTRIBUTE_KEY), and(anyObject(WebGuiceEnvironment.class), capture(capture)));

    replay(servletContext, securityManager, filterChainResolver);

    WebGuiceEnvironment underTest = new WebGuiceEnvironment(filterChainResolver, servletContext, securityManager);

    assertSame(securityManager, underTest.getSecurityManager());
    assertSame(filterChainResolver, underTest.getFilterChainResolver());
    assertSame(securityManager, underTest.getWebSecurityManager());
    assertSame(servletContext, underTest.getServletContext());

    assertSame(underTest, capture.getValue());

    verify(servletContext);
  }
}

代码示例来源:origin: confluentinc/ksql

private void givenDelegateWillReturn(final String line) {
 EasyMock.expect(parsedLine.line()).andReturn(line).anyTimes();
 EasyMock.expect(delegate.parse(anyObject(), anyInt(), anyObject())).andReturn(parsedLine);
 EasyMock.replay(delegate, parsedLine);
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldNotAttemptToCreateCommandTopicIfItExists() {
 EasyMock.resetToStrict(topicClient);
 EasyMock.expect(topicClient.isTopicExists(COMMAND_TOPIC)).andReturn(true);
 EasyMock.expect(topicClient.addTopicConfig(anyObject(), anyObject())).andReturn(false);
 EasyMock.replay(topicClient);
 KsqlRestApplication.ensureCommandTopic(restConfig,
                     topicClient,
                     COMMAND_TOPIC);
 EasyMock.verify(topicClient);
}

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

@Test
public void testServiceAnnouncementPOSTAllExceptionInHandler()
{
 final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
 EasyMock.expect(handler.handlePOSTAll(EasyMock.anyObject(), EasyMock.anyObject()))
     .andThrow(new RuntimeException("test"));
 final ListenerResource resource = new ListenerResource(
   mapper,
   mapper,
   handler
 )
 {
 };
 EasyMock.replay(handler);
 Assert.assertEquals(
   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
   resource.serviceAnnouncementPOSTAll(EMPTY_JSON_MAP.get(), req).getStatus()
 );
 EasyMock.verify(req, handler);
}

代码示例来源:origin: confluentinc/ksql

private StatusResource getTestStatusResource() {
 final StatementExecutor mockStatementExecutor = mock(StatementExecutor.class);
 expect(mockStatementExecutor.getStatuses()).andReturn(mockCommandStatuses);
 for (final Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
  expect(mockStatementExecutor.getStatus(commandEntry.getKey())).andReturn(Optional.of(commandEntry.getValue()));
 }
 expect(mockStatementExecutor.getStatus(anyObject(CommandId.class))).andReturn(Optional.empty());
 replay(mockStatementExecutor);
 return new StatusResource(mockStatementExecutor);
}

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

@Test public void testLog() throws Exception
 {
  ObjectMapper objectMapper = new ObjectMapper();
  DateTime dateTime = DateTimes.nowUtc();
  File logDir = temporaryFolder.newFolder();
  String nativeQueryLogString = dateTime + "\t" + HOST + "\t" + "native";
  String sqlQueryLogString = dateTime + "\t" + HOST + "\t" + "sql";

  FileRequestLogger fileRequestLogger = new FileRequestLogger(objectMapper, scheduler, logDir, "yyyy-MM-dd'.log'");
  fileRequestLogger.start();

  RequestLogLine nativeRequestLogLine = EasyMock.createMock(RequestLogLine.class);
  EasyMock.expect(nativeRequestLogLine.getNativeQueryLine(EasyMock.anyObject())).andReturn(nativeQueryLogString).anyTimes();
  RequestLogLine sqlRequestLogLine = EasyMock.createMock(RequestLogLine.class);
  EasyMock.expect(sqlRequestLogLine.getSqlQueryLine(EasyMock.anyObject())).andReturn(sqlQueryLogString).anyTimes();
  EasyMock.replay(nativeRequestLogLine, sqlRequestLogLine);

  fileRequestLogger.logNativeQuery(nativeRequestLogLine);
  fileRequestLogger.logSqlQuery(sqlRequestLogLine);

  File logFile = new File(logDir, dateTime.toString("yyyy-MM-dd'.log'"));
  String logString = CharStreams.toString(Files.newBufferedReader(logFile.toPath(), StandardCharsets.UTF_8));
  Assert.assertTrue(logString.contains(nativeQueryLogString + "\n" + sqlQueryLogString + "\n"));
  fileRequestLogger.stop();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Before
public void setUp() {
 rpcFactoryMock = EasyMock.createMock(BigQueryRpcFactory.class);
 bigqueryRpcMock = EasyMock.createMock(BigQueryRpc.class);
 EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(BigQueryOptions.class)))
   .andReturn(bigqueryRpcMock);
 EasyMock.replay(rpcFactoryMock);
 options = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
}

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

@Test
public void testServiceAnnouncementPOSTExceptionInHandler()
{
 final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
 EasyMock.expect(handler.handlePOST(
   EasyMock.anyObject(),
   EasyMock.anyObject(),
   EasyMock.anyString()
 )).andThrow(new RuntimeException("test"));
 final ListenerResource resource = new ListenerResource(
   mapper,
   mapper,
   handler
 )
 {
 };
 EasyMock.replay(handler);
 Assert.assertEquals(
   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
   resource.serviceAnnouncementPOST("id", EMPTY_JSON_MAP.get(), req).getStatus()
 );
 EasyMock.verify(req, handler);
}

相关文章