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

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

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

EasyMock.capture介绍

[英]Expect any byte but captures it for later use.
[中]需要任何字节,但捕获它供以后使用。

代码示例

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

@SuppressWarnings("unchecked")
@Test
public void shouldCreateSessionWindowedStreamWithInactiviyGap() {
 EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
 EasyMock.expect(sessionWindowed.aggregate(same(initializer),
   same(aggregator),
   anyObject(Merger.class),
   same(materialized))).andReturn(null);
 EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
 expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
 assertThat(sessionWindows.getValue().inactivityGap(), equalTo(5000L));
 EasyMock.verify(groupedStreamMock);
}

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

@Test
public void testStopSendingAfterClose() {
 replayOnSubscribe();
 EasyMock.expect(session.getAsyncRemote()).andReturn(async).anyTimes();
 final Capture<String> json = EasyMock.newCapture(CaptureType.ALL);
 async.sendText(EasyMock.capture(json), EasyMock.anyObject());
 subscription.request(1);
 subscription.cancel();
 EasyMock.replay(subscription, session, async);
 subscriber.onNext(ImmutableList.of(ImmutableMap.of("a", 1)));
 subscriber.close();
 subscriber.onNext(ImmutableList.of(ImmutableMap.of("b", 2), ImmutableMap.of("c", 3)));
 assertEquals(ImmutableList.of("{\"a\":1}"), json.getValues());
 EasyMock.verify(subscription, session, async);
}

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

@Test
public void testGetZoneNotFound() {
 EasyMock.reset(batchMock);
 Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
 Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
 batchMock.addGetZone(
   EasyMock.eq(ZONE_NAME), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
 EasyMock.replay(batchMock);
 DnsBatchResult<Zone> batchResult = dnsBatch.getZone(ZONE_NAME);
 assertEquals(0, capturedOptions.getValue().size());
 GoogleJsonError error = new GoogleJsonError();
 error.setCode(404);
 RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
 capturedCallback.onFailure(error);
 assertNull(batchResult.get());
}

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

@Test
public void testReset()
{
 Capture<String> id1 = Capture.newInstance();
 Capture<String> id2 = Capture.newInstance();
 EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)).times(2);
 EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id1), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(true);
 EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id2), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(false);
 replayAll();
 Response response = supervisorResource.reset("my-id");
 Assert.assertEquals(200, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("id", "my-id"), response.getEntity());
 response = supervisorResource.reset("my-id-2");
 Assert.assertEquals(404, response.getStatus());
 Assert.assertEquals("my-id", id1.getValue());
 Assert.assertEquals("my-id-2", id2.getValue());
 verifyAll();
 resetAll();
 EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.absent());
 replayAll();
 response = supervisorResource.terminate("my-id");
 Assert.assertEquals(503, response.getStatus());
 verifyAll();
}

代码示例来源: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());
}

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

@Test
public void testSanity() throws Exception {
 replayOnSubscribe();
 EasyMock.expect(session.getAsyncRemote()).andReturn(async).anyTimes();
 final Capture<String> json = EasyMock.newCapture(CaptureType.ALL);
 async.sendText(EasyMock.capture(json), EasyMock.anyObject());
 EasyMock.expectLastCall().times(3);
 subscription.request(1);
 EasyMock.expectLastCall().once();
 session.close(EasyMock.anyObject());
 EasyMock.expectLastCall().once();
 subscription.cancel();
 EasyMock.replay(subscription, session, async);
 subscriber.onNext(ImmutableList.of(ImmutableMap.of("a", 1), ImmutableMap.of("b", 2), ImmutableMap.of("c", 3)));
 assertEquals(ImmutableList.of("{\"a\":1}","{\"b\":2}","{\"c\":3}"), json.getValues());
 subscriber.onComplete();
 subscriber.close();
 EasyMock.verify(subscription, session, async);
}

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

@SuppressWarnings("unchecked")
@Test
public void shouldGetMergerForSessionWindowsFromUdafAggregator() {
 EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
 EasyMock.expect(sessionWindowed.aggregate(same(initializer),
   same(aggregator),
   same(merger),
   same(materialized))).andReturn(null);
 EasyMock.expect(aggregator.getMerger()).andReturn(merger);
 EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
 expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
 EasyMock.verify(aggregator);
}

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

@Test
public void shouldExitAndDrainIfQueryStopsRunning() throws Exception {
 // Given:
 expect(queryMetadata.isRunning()).andReturn(true).andReturn(false);
 expect(rowQueue.drainTo(capture(drainCapture))).andAnswer(rows("Row1", "Row2", "Row3"));
 createWriter();
 // When:
 writer.write(out);
 // Then:
 final List<String> lines = getOutput(out);
 assertThat(lines, hasItems(
   containsString("Row1"),
   containsString("Row2"),
   containsString("Row3")));
}

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

@Test
 public void testOnError() throws Exception {
  replayOnSubscribe();

  final Capture<CloseReason> reason = EasyMock.newCapture();
  EasyMock.expect(session.getId()).andReturn("abc123").once();
  session.close(EasyMock.capture(reason));
  EasyMock.expectLastCall().once();
  subscription.cancel();
  EasyMock.expectLastCall().once();

  EasyMock.replay(subscription, session);

  subscriber.onError(new RuntimeException("streams died"));
  subscriber.close();

  assertEquals("streams exception", reason.getValue().getReasonPhrase());
  assertEquals(CloseCodes.UNEXPECTED_CONDITION, reason.getValue().getCloseCode());

  EasyMock.verify(subscription, session);
 }
}

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

@Test
public void testProjectGetWithOptions() {
 Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(dnsRpcMock.getProject(EasyMock.capture(capturedOptions)))
   .andReturn(PROJECT_INFO.toPb());
 EasyMock.replay(dnsRpcMock);
 dns = options.getService(); // creates DnsImpl
 ProjectInfo projectInfo = dns.getProject(PROJECT_FIELDS);
 String selector = (String) capturedOptions.getValue().get(PROJECT_FIELDS.getRpcOption());
 assertEquals(PROJECT_INFO, projectInfo);
 assertTrue(selector.contains(Dns.ProjectField.QUOTA.getSelector()));
 assertTrue(selector.contains(Dns.ProjectField.PROJECT_ID.getSelector()));
}

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

@Test
public void testFailedNew() throws Exception
 EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
 EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
 EasyMock.expect(lookupCoordinatorManager.updateLookups(
   EasyMock.eq(SINGLE_TIER_MAP),
   EasyMock.capture(auditInfoCapture)
 )).andReturn(false).once();
 EasyMock.replay(lookupCoordinatorManager, request);
 );
 Assert.assertEquals(500, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
 Assert.assertTrue(auditInfoCapture.hasCaptured());
 final AuditInfo auditInfo = auditInfoCapture.getValue();
 Assert.assertEquals(author, auditInfo.getAuthor());
 Assert.assertEquals(comment, auditInfo.getComment());
 Assert.assertEquals(ip, auditInfo.getIp());

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

@Test
public void testExceptionalNew() throws Exception
 EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
 EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
 EasyMock.expect(lookupCoordinatorManager.updateLookups(
   EasyMock.eq(SINGLE_TIER_MAP),
   EasyMock.capture(auditInfoCapture)
 )).andThrow(new RuntimeException(errMsg)).once();
 EasyMock.replay(lookupCoordinatorManager, request);
 );
 Assert.assertEquals(500, response.getStatus());
 Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
 Assert.assertTrue(auditInfoCapture.hasCaptured());
 final AuditInfo auditInfo = auditInfoCapture.getValue();
 Assert.assertEquals(author, auditInfo.getAuthor());
 Assert.assertEquals(comment, auditInfo.getComment());
 Assert.assertEquals(ip, auditInfo.getIp());

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

@Test
public void testCreateImageWithOptions() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(computeRpcMock.createImage(eq(IMAGE.toPb()), capture(capturedOptions)))
   .andReturn(globalOperation.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Operation operation = compute.create(IMAGE, OPERATION_OPTION_FIELDS);
 String selector =
   (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(globalOperation, operation);
}

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

@Test
public void testCreateNetworkWithOptions() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(computeRpcMock.createNetwork(eq(NETWORK.toPb()), capture(capturedOptions)))
   .andReturn(globalOperation.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Operation operation = compute.create(NETWORK, OPERATION_OPTION_FIELDS);
 String selector =
   (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(globalOperation, operation);
}

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

@Test
public void testGetRegionWithSelectedFields() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(computeRpcMock.getRegion(eq(REGION_ID.getRegion()), capture(capturedOptions)))
   .andReturn(REGION.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Region region = compute.getRegion(REGION_ID.getRegion(), REGION_OPTION_FIELDS);
 String selector = (String) capturedOptions.getValue().get(REGION_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(REGION, region);
}

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

@Test
public void testGetZoneWithSelectedFields() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(computeRpcMock.getZone(eq(ZONE_ID.getZone()), capture(capturedOptions)))
   .andReturn(ZONE.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Zone zone = compute.getZone(ZONE_ID.getZone(), ZONE_OPTION_FIELDS);
 String selector = (String) capturedOptions.getValue().get(ZONE_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(ZONE, zone);
}

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

@Test
public void testSimpleNew() throws Exception
 EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
 EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
 final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
 final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
   LookupCoordinatorManager.class);
 EasyMock.expect(lookupCoordinatorManager.updateLookups(
   EasyMock.eq(SINGLE_TIER_MAP),
   EasyMock.capture(auditInfoCapture)
 )).andReturn(true).once();
 EasyMock.replay(lookupCoordinatorManager, request);
 final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
   lookupCoordinatorManager,
 );
 Assert.assertEquals(202, response.getStatus());
 Assert.assertTrue(auditInfoCapture.hasCaptured());
 final AuditInfo auditInfo = auditInfoCapture.getValue();
 Assert.assertEquals(author, auditInfo.getAuthor());
 Assert.assertEquals(comment, auditInfo.getComment());
 Assert.assertEquals(ip, auditInfo.getIp());

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

@Test
public void testDeleteSnapshotWithSelectedFields_Operation() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(
     computeRpcMock.deleteSnapshot(eq(SNAPSHOT_ID.getSnapshot()), capture(capturedOptions)))
   .andReturn(globalOperation.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Operation operation = compute.deleteSnapshot(SNAPSHOT_ID, OPERATION_OPTION_FIELDS);
 String selector =
   (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(globalOperation, operation);
}

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

@Test
public void testCreateGlobalAddressWithOptions() {
 Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
 EasyMock.expect(
     computeRpcMock.createGlobalAddress(eq(GLOBAL_ADDRESS.toPb()), capture(capturedOptions)))
   .andReturn(globalOperation.toPb());
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Operation operation = compute.create(GLOBAL_ADDRESS, OPERATION_OPTION_FIELDS);
 String selector =
   (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
 assertTrue(selector.contains("selfLink"));
 assertTrue(selector.contains("id"));
 assertTrue(selector.contains("description"));
 assertEquals(23, selector.length());
 assertEquals(globalOperation, operation);
}

相关文章