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

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

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

EasyMock.reset介绍

[英]Resets the given mock object (more exactly: the control of the mock object). For details, see the EasyMock documentation.
[中]重置给定的模拟对象(更确切地说:模拟对象的控件)。有关详细信息,请参阅EasyMock文档。

代码示例

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

private void runWithMocks(Runnable toRun, Object... mocks)
{
 EasyMock.replay(mocks);
 toRun.run();
 EasyMock.verify(mocks);
 EasyMock.reset(mocks);
}

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

private void givenPredicateWillReturnTrue() {
  EasyMock.reset(cliLinePredicate);
  EasyMock.expect(cliLinePredicate.test(anyString())).andReturn(true);
  EasyMock.replay(cliLinePredicate);
 }
}

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

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 shouldInvokeParserCorrectly() {
 // Given:
 reset(parser);
 expect(parser.parse("prop-1", "new-val")).andReturn("parsed-new-val");
 replay(parser);
 // When:
 propsWithMockParser.set("prop-1", "new-val");
 // Then:
 assertThat(propsWithMockParser.toMap().get("prop-1"), is("parsed-new-val"));
 verify(parser);
}

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

@Test
public void shouldFailIfIsNotAcceptingStatements() throws Exception {
 // Given:
 final String queryString = "SELECT * FROM test_stream;";
 reset(mockKsqlEngine);
 expect(mockKsqlEngine.isAcceptingStatements()).andReturn(false);
 replay(mockKsqlEngine);
 // When:
 final Response response =
   testResource.streamQuery(new KsqlRequest(queryString, Collections.emptyMap(), null));
 // Then:
 assertThat(response.getStatus(), equalTo(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
 final KsqlErrorMessage errorMessage = (KsqlErrorMessage)response.getEntity();
 assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_SERVER_ERROR));
 assertThat(errorMessage.getMessage(), containsString("Cluster has been terminated."));
}

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

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIfParserThrows() {
 // Given:
 reset(parser);
 expect(parser.parse("prop-1", "new-val"))
   .andThrow(new IllegalArgumentException("Boom"));
 replay(parser);
 // When:
 propsWithMockParser.set("prop-1", "new-val");
}

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

@Test
public void testGoodQueryWithNullAcceptHeader() throws IOException
{
 final String acceptHeader = null;
 final String contentTypeHeader = MediaType.APPLICATION_JSON;
 EasyMock.reset(testServletRequest);
 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.expect(testServletRequest.getHeader("Accept")).andReturn(acceptHeader).anyTimes();
 EasyMock.expect(testServletRequest.getContentType()).andReturn(contentTypeHeader).anyTimes();
 EasyMock.expect(testServletRequest.getHeader(QueryResource.HEADER_IF_NONE_MATCH)).andReturn(null).anyTimes();
 EasyMock.expect(testServletRequest.getRemoteAddr()).andReturn("localhost").anyTimes();
 EasyMock.replay(testServletRequest);
 Response response = queryResource.doPost(
   new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")),
   null /*pretty*/,
   testServletRequest
 );
 Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
 //since accept header is null, the response content type should be same as the value of 'Content-Type' header
 Assert.assertEquals(contentTypeHeader, (response.getMetadata().get("Content-Type").get(0)).toString());
 Assert.assertNotNull(response);
}

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

@Test
public void testGoodQueryWithEmptyAcceptHeader() throws IOException
{
 final String acceptHeader = "";
 final String contentTypeHeader = MediaType.APPLICATION_JSON;
 EasyMock.reset(testServletRequest);
 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.expect(testServletRequest.getHeader("Accept")).andReturn(acceptHeader).anyTimes();
 EasyMock.expect(testServletRequest.getContentType()).andReturn(contentTypeHeader).anyTimes();
 EasyMock.expect(testServletRequest.getHeader(QueryResource.HEADER_IF_NONE_MATCH)).andReturn(null).anyTimes();
 EasyMock.expect(testServletRequest.getRemoteAddr()).andReturn("localhost").anyTimes();
 EasyMock.replay(testServletRequest);
 Response response = queryResource.doPost(
   new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")),
   null /*pretty*/,
   testServletRequest
 );
 Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
 //since accept header is empty, the response content type should be same as the value of 'Content-Type' header
 Assert.assertEquals(contentTypeHeader, (response.getMetadata().get("Content-Type").get(0)).toString());
 Assert.assertNotNull(response);
}

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

@Test
public void testLookupDiscoverAll()
{
 final Set<String> fakeChildren = ImmutableSet.of("tier1", "tier2");
 EasyMock.reset(lookupNodeDiscovery);
 EasyMock.expect(lookupNodeDiscovery.getAllTiers())
     .andReturn(fakeChildren)
     .once();
 EasyMock.replay(lookupNodeDiscovery);
 final LookupCoordinatorManager manager = new LookupCoordinatorManager(
   druidNodeDiscoveryProvider,
   configManager,
   lookupCoordinatorManagerConfig,
   EasyMock.createMock(LookupCoordinatorManager.LookupsCommunicator.class),
   lookupNodeDiscovery
 );
 manager.start();
 Assert.assertEquals(fakeChildren, manager.discoverTiers());
 EasyMock.verify(lookupNodeDiscovery);
}

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

@Override
@Before
public void setUp() throws Exception
{
 super.setUp();
 EasyMock.reset(lookupReferencesManager);
 LookupExtractorFactory lookupExtractorFactory1 = new MapLookupExtractorFactory(ImmutableMap.of(
   "key",
   "value",
   "key2",
   "value2"
 ), false);
 EasyMock.expect(lookupReferencesManager.get("lookupId1")).andReturn(
   new LookupExtractorFactoryContainer(
     "v0",
     lookupExtractorFactory1
   )
 ).anyTimes();
 EasyMock.replay(lookupReferencesManager);
}

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

@Test
public void testDiscoverNodesInTier()
{
 EasyMock.reset(lookupNodeDiscovery);
 EasyMock.expect(lookupNodeDiscovery.getNodesInTier("tier"))
     .andReturn(
       ImmutableSet.of(
         HostAndPortWithScheme.fromParts("http", "h1", 8080),
         HostAndPortWithScheme.fromParts("http", "h2", 8080)
       )
     )
     .once();
 EasyMock.replay(lookupNodeDiscovery);
 final LookupCoordinatorManager manager = new LookupCoordinatorManager(
   druidNodeDiscoveryProvider,
   configManager,
   lookupCoordinatorManagerConfig,
   EasyMock.createMock(LookupCoordinatorManager.LookupsCommunicator.class),
   lookupNodeDiscovery
 );
 manager.start();
 Assert.assertEquals(
   ImmutableSet.of(
     HostAndPort.fromParts("h1", 8080),
     HostAndPort.fromParts("h2", 8080)
   ),
   ImmutableSet.copyOf(manager.discoverNodesInTier("tier")));
 EasyMock.verify(lookupNodeDiscovery);
}

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

@Before
public void setUp() throws IOException
{
 SERVICE_EMITTER.flush();
 EVENT_EMITS.set(0L);
 EasyMock.reset(lookupNodeDiscovery);
 EasyMock.reset(configManager);
 EasyMock.expect(
   configManager.watch(
     EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY),
     EasyMock.<TypeReference>anyObject(),
     EasyMock.<AtomicReference>isNull()
   )
 ).andReturn(
   new AtomicReference<>(null)
 ).anyTimes();
 EasyMock.expect(
   configManager.watch(
     EasyMock.eq(LookupCoordinatorManager.OLD_LOOKUP_CONFIG_KEY),
     EasyMock.<TypeReference>anyObject(),
     EasyMock.<AtomicReference>isNull()
   )
 ).andReturn(
   new AtomicReference<>(null)
 ).anyTimes();
 EasyMock.replay(configManager);
}

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

@Test
public void testFailedResource()
{
 primePool();
 EasyMock.expect(resourceFactory.isGood("billy1")).andReturn(false).times(1);
 resourceFactory.close("billy1");
 EasyMock.expectLastCall();
 EasyMock.expect(resourceFactory.generate("billy")).andReturn("billy2").times(1);
 EasyMock.replay(resourceFactory);
 ResourceContainer<String> billy = pool.take("billy");
 Assert.assertEquals("billy2", billy.get());
 billy.returnResource();
 EasyMock.verify(resourceFactory);
 EasyMock.reset(resourceFactory);
}

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

@Test
public void testTimedOutResource() throws Exception
{
 resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class);
 pool = new ResourcePool<String, String>(
   resourceFactory,
   new ResourcePoolConfig(2, TimeUnit.MILLISECONDS.toMillis(10))
 );
 EasyMock.expect(resourceFactory.generate("billy")).andAnswer(new StringIncrementingAnswer("billy")).times(2);
 EasyMock.expect(resourceFactory.isGood("billy0")).andReturn(true).times(1);
 EasyMock.replay(resourceFactory);
 ResourceContainer<String> billyString = pool.take("billy");
 Assert.assertEquals("billy0", billyString.get());
 EasyMock.verify(resourceFactory);
 EasyMock.reset(resourceFactory);
 billyString.returnResource();
 //make sure resources have been timed out.
 Thread.sleep(100);
 EasyMock.expect(resourceFactory.generate("billy")).andReturn("billy1").times(1);
 resourceFactory.close("billy1");
 EasyMock.expect(resourceFactory.isGood("billy1")).andReturn(true).times(1);
 EasyMock.replay(resourceFactory);
 ResourceContainer<String> billy = pool.take("billy");
 Assert.assertEquals("billy1", billy.get());
 billy.returnResource();
 EasyMock.verify(resourceFactory);
 EasyMock.reset(resourceFactory);
}

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

private void primePool()
{
 EasyMock.expect(resourceFactory.generate("billy")).andAnswer(new StringIncrementingAnswer("billy")).times(2);
 EasyMock.expect(resourceFactory.generate("sally")).andAnswer(new StringIncrementingAnswer("sally")).times(2);
 EasyMock.expect(resourceFactory.isGood("billy0")).andReturn(true).times(1);
 EasyMock.expect(resourceFactory.isGood("sally0")).andReturn(true).times(1);
 EasyMock.replay(resourceFactory);
 ResourceContainer<String> billyString = pool.take("billy");
 ResourceContainer<String> sallyString = pool.take("sally");
 Assert.assertEquals("billy0", billyString.get());
 Assert.assertEquals("sally0", sallyString.get());
 EasyMock.verify(resourceFactory);
 EasyMock.reset(resourceFactory);
 billyString.returnResource();
 sallyString.returnResource();
}

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

@Test
public void testUpdateLookupAdds()
{
 final LookupCoordinatorManager manager = new LookupCoordinatorManager(
   client,
   druidNodeDiscoveryProvider,
   mapper,
   configManager,
   lookupCoordinatorManagerConfig
 )
 {
  @Override
  public Map<String, Map<String, LookupExtractorFactoryMapContainer>> getKnownLookups()
  {
   return EMPTY_TIERED_LOOKUP;
  }
 };
 manager.start();
 final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
 EasyMock.reset(configManager);
 EasyMock.expect(configManager.set(
           EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY),
           EasyMock.eq(TIERED_LOOKUP_MAP_V0),
           EasyMock.eq(auditInfo)
         )).andReturn(SetResult.ok()).once();
 EasyMock.replay(configManager);
 manager.updateLookup(LOOKUP_TIER, SINGLE_LOOKUP_NAME, SINGLE_LOOKUP_SPEC_V0, auditInfo);
 EasyMock.verify(configManager);
}

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

@Test
public void testUpdateLookupsUpdates()
{
 final LookupCoordinatorManager manager = new LookupCoordinatorManager(
   client,
   druidNodeDiscoveryProvider,
   mapper,
   configManager,
   lookupCoordinatorManagerConfig
 )
 {
  @Override
  public Map<String, Map<String, LookupExtractorFactoryMapContainer>> getKnownLookups()
  {
   return TIERED_LOOKUP_MAP_V0;
  }
 };
 manager.start();
 final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
 EasyMock.reset(configManager);
 EasyMock.expect(configManager.set(
           EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY),
           EasyMock.eq(TIERED_LOOKUP_MAP_V1),
           EasyMock.eq(auditInfo)
         )).andReturn(SetResult.ok()).once();
 EasyMock.replay(configManager);
 manager.updateLookups(TIERED_LOOKUP_MAP_V1, auditInfo);
 EasyMock.verify(configManager);
}

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

@Test
public void testDeleteZoneOnSuccess() {
 EasyMock.reset(batchMock);
 Capture<RpcBatch.Callback<Void>> callback = Capture.newInstance();
 batchMock.addDeleteZone(EasyMock.eq(ZONE_NAME), EasyMock.capture(callback));
 EasyMock.replay(batchMock);
 DnsBatchResult<Boolean> batchResult = dnsBatch.deleteZone(ZONE_NAME);
 assertNotNull(callback.getValue());
 RpcBatch.Callback<Void> capturedCallback = callback.getValue();
 Void result = null;
 capturedCallback.onSuccess(result);
 assertTrue(batchResult.get());
}

相关文章