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

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

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

EasyMock.expectLastCall介绍

[英]Returns the expectation setter for the last expected invocation in the current thread. This method is used for expected invocations on void methods.
[中]返回当前线程中最后一次预期调用的预期设置程序。此方法用于对void方法的预期调用。

代码示例

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

@Test
public void shouldFlushWriterWhenOutputtingLongMessage() {
 // Given:
 mockPrintWriter.flush();
 EasyMock.expectLastCall();
 EasyMock.replay(mockPrintWriter);
 // When:
 WelcomeMsgUtils.displayWelcomeMessage(80, mockPrintWriter);
 // Then:
 EasyMock.verify(mockPrintWriter);
}

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

private void expectAuthorizationTokenCheck()
{
 AuthenticationResult authenticationResult = new AuthenticationResult("druid", "druid", null, null);
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
     .andReturn(authenticationResult)
     .atLeastOnce();
 req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, false);
 EasyMock.expectLastCall().anyTimes();
 req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
 EasyMock.expectLastCall().anyTimes();
}

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

@Test(expected = KsqlRestClientException.class)
public void shouldThrowIfRestClientThrowsOnSet() {
 restClient.setServerAddress("localhost:8088");
 expectLastCall().andThrow(new KsqlRestClientException("Boom"));
 replay(restClient);
 command.execute(ImmutableList.of("localhost:8088"), terminal);
}

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

private void replayOnSubscribe() {
 subscription.request(1);
 EasyMock.expectLastCall().once();
 EasyMock.replay(subscription);
 subscriber.onSubscribe(subscription);
 EasyMock.verify(subscription);
 EasyMock.reset(subscription);
}

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

@Test
 public void shouldFlushWriterWhenOutputtingShortMessage() {
  // Given:
  mockPrintWriter.flush();
  EasyMock.expectLastCall();
  EasyMock.replay(mockPrintWriter);

  // When:
  WelcomeMsgUtils.displayWelcomeMessage(10, mockPrintWriter);

  // Then:
  EasyMock.verify(mockPrintWriter);
 }
}

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

@Test
public void shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber()
  throws Exception {
 // Given:
 commandQueue.ensureConsumedPast(anyLong(), anyObject());
 expectLastCall().andThrow(new TimeoutException("whoops"));
 replay(commandQueue);
 // Expect
 expectedException.expect(KsqlRestException.class);
 expectedException.expect(exceptionStatusCode(is(Code.SERVICE_UNAVAILABLE)));
 expectedException.expect(exceptionKsqlErrorMessage(errorMessage(is("whoops"))));
 expectedException.expect(
   exceptionKsqlErrorMessage(errorCode(is(Errors.ERROR_CODE_COMMAND_QUEUE_CATCHUP_TIMEOUT))));
 // When:
 testResource.streamQuery(new KsqlRequest(queryString, Collections.emptyMap(), 3L));
}

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

private void setUpRequestExpectations(String producerId, String producerSequenceValue)
 {
  EasyMock.reset(req);
  EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED))
      .andReturn(null)
      .anyTimes();
  EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
  EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
      .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT)
      .anyTimes();
  req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
  EasyMock.expectLastCall().anyTimes();

  EasyMock.expect(req.getContentType()).andReturn("application/json");
  EasyMock.expect(req.getHeader("X-Firehose-Producer-Id")).andReturn(producerId);

  if (producerId != null) {
   EasyMock.expect(req.getHeader("X-Firehose-Producer-Seq")).andReturn(producerSequenceValue);
  }

  EasyMock.replay(req);
 }
}

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

@Test
public void shouldStopAppOnJoin() throws Exception {
 // Given:
 executable.stop();
 expectLastCall();
 replay(executable);
 // When:
 main.tryStartApp();
 // Then:
 verify(executable);
}

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

@Test
public void testGoodQuery() throws IOException
{
 EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED))
     .andReturn(null)
     .anyTimes();
 EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
 EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
     .andReturn(authenticationResult)
     .anyTimes();
 testServletRequest.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(testServletRequest);
 Response response = queryResource.doPost(
   new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")),
   null /*pretty*/,
   testServletRequest
 );
 Assert.assertNotNull(response);
}

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

@Test
public void shouldRestClientServerAddressWhenNonEmptyStringArg() {
 expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO));
 restClient.setServerAddress(VALID_SERVER_ADDRESS);
 expectLastCall();
 replay(restClient);
 command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal);
 verify(restClient);
}

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

@Test
public void shouldCreateCommandTopicIfItDoesNotExist() {
 topicClient.createTopic(COMMAND_TOPIC,
   1,
   (short) 1,
   commandTopicConfig);
 EasyMock.expectLastCall();
 EasyMock.replay(topicClient);
 KsqlRestApplication.ensureCommandTopic(restConfig,
                     topicClient,
                     COMMAND_TOPIC);
 EasyMock.verify(topicClient);
}

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

@Test(timeout = 60_000L)
public void testShutdownWithPrevTime() throws Exception
{
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED))
     .andReturn(null)
     .anyTimes();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
     .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT)
     .anyTimes();
 req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(req);
 firehose.shutdown(DateTimes.nowUtc().minusMinutes(2).toString(), req);
 while (!firehose.isClosed()) {
  Thread.sleep(50);
 }
}

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

@Test(timeout = 60_000L)
public void testShutdown() throws Exception
{
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED))
     .andReturn(null)
     .anyTimes();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
     .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT)
     .anyTimes();
 req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(req);
 firehose.shutdown(DateTimes.nowUtc().plusMillis(100).toString(), req);
 while (!firehose.isClosed()) {
  Thread.sleep(50);
 }
}

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

@Test
public void testTerminateAll()
{
 EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
 supervisorManager.stopAndRemoveAllSupervisors();
 EasyMock.expectLastCall();
 replayAll();
 Response response = supervisorResource.terminateAll();
 Assert.assertEquals(200, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity());
 verifyAll();
}

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

@Test
 public void cleanup()
 {
  PooledTopNAlgorithm pooledTopNAlgorithm = new PooledTopNAlgorithm(EasyMock.mock(StorageAdapter.class), null, null);
  PooledTopNAlgorithm.PooledTopNParams params = EasyMock.createMock(PooledTopNAlgorithm.PooledTopNParams.class);
  ResourceHolder<ByteBuffer> resourceHolder = EasyMock.createMock(ResourceHolder.class);
  EasyMock.expect(params.getResultsBufHolder()).andReturn(resourceHolder).times(1);
  EasyMock.expect(resourceHolder.get()).andReturn(ByteBuffer.allocate(1)).times(1);
  resourceHolder.close();
  EasyMock.expectLastCall().once();
  EasyMock.replay(params);
  EasyMock.replay(resourceHolder);
  pooledTopNAlgorithm.cleanup(params);
  EasyMock.verify(params);
  EasyMock.verify(resourceHolder);
 }
}

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

@Test
public void shouldPrintServerAddressWhenEmptyStringArg() throws Exception {
 expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO));
 expect(restClient.getServerAddress()).andReturn(new URI(INITIAL_SERVER_ADDRESS));
 restClient.setServerAddress(anyString());
 expectLastCall().andThrow(new AssertionError("should not set address"));
 replay(restClient);
 command.execute(ImmutableList.of(), terminal);
 assertThat(out.toString(), equalTo(INITIAL_SERVER_ADDRESS + "\n"));
}

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

@Test
public void testSuspendAll()
{
 EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
 supervisorManager.suspendOrResumeAllSupervisors(true);
 EasyMock.expectLastCall();
 replayAll();
 Response response = supervisorResource.suspendAll();
 Assert.assertEquals(200, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity());
 verifyAll();
}

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

@Test
public void testResumeAll()
{
 EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
 supervisorManager.suspendOrResumeAllSupervisors(false);
 EasyMock.expectLastCall();
 replayAll();
 Response response = supervisorResource.resumeAll();
 Assert.assertEquals(200, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity());
 verifyAll();
}

相关文章