org.easymock.Capture.newInstance()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(17.4k)|赞(0)|评价(0)|浏览(126)

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

Capture.newInstance介绍

[英]Create a new capture instance that will keep only the last captured value
[中]创建一个新的捕获实例,该实例将只保留最后捕获的值

代码示例

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

  1. @Test
  2. public void testReset()
  3. {
  4. Capture<String> id1 = Capture.newInstance();
  5. Capture<String> id2 = Capture.newInstance();
  6. EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)).times(2);
  7. EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id1), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(true);
  8. EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id2), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(false);
  9. replayAll();
  10. Response response = supervisorResource.reset("my-id");
  11. Assert.assertEquals(200, response.getStatus());
  12. Assert.assertEquals(ImmutableMap.of("id", "my-id"), response.getEntity());
  13. response = supervisorResource.reset("my-id-2");
  14. Assert.assertEquals(404, response.getStatus());
  15. Assert.assertEquals("my-id", id1.getValue());
  16. Assert.assertEquals("my-id-2", id2.getValue());
  17. verifyAll();
  18. resetAll();
  19. EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.absent());
  20. replayAll();
  21. response = supervisorResource.terminate("my-id");
  22. Assert.assertEquals(503, response.getStatus());
  23. verifyAll();
  24. }

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

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

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

  1. @Test
  2. public void testCreateImageWithOptions() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(computeRpcMock.createImage(eq(IMAGE.toPb()), capture(capturedOptions)))
  5. .andReturn(globalOperation.toPb());
  6. EasyMock.replay(computeRpcMock);
  7. compute = options.getService();
  8. Operation operation = compute.create(IMAGE, OPERATION_OPTION_FIELDS);
  9. String selector =
  10. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  11. assertTrue(selector.contains("selfLink"));
  12. assertTrue(selector.contains("id"));
  13. assertTrue(selector.contains("description"));
  14. assertEquals(23, selector.length());
  15. assertEquals(globalOperation, operation);
  16. }

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

  1. @Test
  2. public void testCreateNetworkWithOptions() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(computeRpcMock.createNetwork(eq(NETWORK.toPb()), capture(capturedOptions)))
  5. .andReturn(globalOperation.toPb());
  6. EasyMock.replay(computeRpcMock);
  7. compute = options.getService();
  8. Operation operation = compute.create(NETWORK, OPERATION_OPTION_FIELDS);
  9. String selector =
  10. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  11. assertTrue(selector.contains("selfLink"));
  12. assertTrue(selector.contains("id"));
  13. assertTrue(selector.contains("description"));
  14. assertEquals(23, selector.length());
  15. assertEquals(globalOperation, operation);
  16. }

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

  1. @Test
  2. public void testFailedNew() throws Exception
  3. EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
  4. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  5. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  6. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  7. LookupCoordinatorManager.class);
  8. EasyMock.expect(lookupCoordinatorManager.updateLookups(
  9. EasyMock.eq(SINGLE_TIER_MAP),
  10. EasyMock.capture(auditInfoCapture)
  11. )).andReturn(false).once();
  12. EasyMock.replay(lookupCoordinatorManager, request);
  13. );
  14. Assert.assertEquals(500, response.getStatus());
  15. Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
  16. Assert.assertTrue(auditInfoCapture.hasCaptured());
  17. final AuditInfo auditInfo = auditInfoCapture.getValue();
  18. Assert.assertEquals(author, auditInfo.getAuthor());
  19. Assert.assertEquals(comment, auditInfo.getComment());
  20. Assert.assertEquals(ip, auditInfo.getIp());

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

  1. @Test
  2. public void testGetZoneWithSelectedFields() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(computeRpcMock.getZone(eq(ZONE_ID.getZone()), capture(capturedOptions)))
  5. .andReturn(ZONE.toPb());
  6. EasyMock.replay(computeRpcMock);
  7. compute = options.getService();
  8. Zone zone = compute.getZone(ZONE_ID.getZone(), ZONE_OPTION_FIELDS);
  9. String selector = (String) capturedOptions.getValue().get(ZONE_OPTION_FIELDS.getRpcOption());
  10. assertTrue(selector.contains("selfLink"));
  11. assertTrue(selector.contains("id"));
  12. assertTrue(selector.contains("description"));
  13. assertEquals(23, selector.length());
  14. assertEquals(ZONE, zone);
  15. }

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

  1. @Test
  2. public void testGetRegionWithSelectedFields() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(computeRpcMock.getRegion(eq(REGION_ID.getRegion()), capture(capturedOptions)))
  5. .andReturn(REGION.toPb());
  6. EasyMock.replay(computeRpcMock);
  7. compute = options.getService();
  8. Region region = compute.getRegion(REGION_ID.getRegion(), REGION_OPTION_FIELDS);
  9. String selector = (String) capturedOptions.getValue().get(REGION_OPTION_FIELDS.getRpcOption());
  10. assertTrue(selector.contains("selfLink"));
  11. assertTrue(selector.contains("id"));
  12. assertTrue(selector.contains("description"));
  13. assertEquals(23, selector.length());
  14. assertEquals(REGION, region);
  15. }

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

  1. @Test
  2. public void testDeleteSnapshotWithSelectedFields_Operation() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.deleteSnapshot(eq(SNAPSHOT_ID.getSnapshot()), capture(capturedOptions)))
  6. .andReturn(globalOperation.toPb());
  7. EasyMock.replay(computeRpcMock);
  8. compute = options.getService();
  9. Operation operation = compute.deleteSnapshot(SNAPSHOT_ID, OPERATION_OPTION_FIELDS);
  10. String selector =
  11. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  12. assertTrue(selector.contains("selfLink"));
  13. assertTrue(selector.contains("id"));
  14. assertTrue(selector.contains("description"));
  15. assertEquals(23, selector.length());
  16. assertEquals(globalOperation, operation);
  17. }

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

  1. @Test
  2. public void testCreateGlobalAddressWithOptions() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.createGlobalAddress(eq(GLOBAL_ADDRESS.toPb()), capture(capturedOptions)))
  6. .andReturn(globalOperation.toPb());
  7. EasyMock.replay(computeRpcMock);
  8. compute = options.getService();
  9. Operation operation = compute.create(GLOBAL_ADDRESS, OPERATION_OPTION_FIELDS);
  10. String selector =
  11. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  12. assertTrue(selector.contains("selfLink"));
  13. assertTrue(selector.contains("id"));
  14. assertTrue(selector.contains("description"));
  15. assertEquals(23, selector.length());
  16. assertEquals(globalOperation, operation);
  17. }

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

  1. @Test
  2. public void testExceptionalNew() throws Exception
  3. EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
  4. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  5. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  6. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  7. LookupCoordinatorManager.class);
  8. EasyMock.expect(lookupCoordinatorManager.updateLookups(
  9. EasyMock.eq(SINGLE_TIER_MAP),
  10. EasyMock.capture(auditInfoCapture)
  11. )).andThrow(new RuntimeException(errMsg)).once();
  12. EasyMock.replay(lookupCoordinatorManager, request);
  13. );
  14. Assert.assertEquals(500, response.getStatus());
  15. Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
  16. Assert.assertTrue(auditInfoCapture.hasCaptured());
  17. final AuditInfo auditInfo = auditInfoCapture.getValue();
  18. Assert.assertEquals(author, auditInfo.getAuthor());
  19. Assert.assertEquals(comment, auditInfo.getComment());
  20. Assert.assertEquals(ip, auditInfo.getIp());

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

  1. @Test
  2. public void testGetZoneNotFound() {
  3. EasyMock.reset(batchMock);
  4. Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
  5. Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
  6. batchMock.addGetZone(
  7. EasyMock.eq(ZONE_NAME), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
  8. EasyMock.replay(batchMock);
  9. DnsBatchResult<Zone> batchResult = dnsBatch.getZone(ZONE_NAME);
  10. assertEquals(0, capturedOptions.getValue().size());
  11. GoogleJsonError error = new GoogleJsonError();
  12. error.setCode(404);
  13. RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
  14. capturedCallback.onFailure(error);
  15. assertNull(batchResult.get());
  16. }

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

  1. @Test
  2. public void testSimpleNew() throws Exception
  3. EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
  4. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  5. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  6. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  7. LookupCoordinatorManager.class);
  8. EasyMock.expect(lookupCoordinatorManager.updateLookups(
  9. EasyMock.eq(SINGLE_TIER_MAP),
  10. EasyMock.capture(auditInfoCapture)
  11. )).andReturn(true).once();
  12. EasyMock.replay(lookupCoordinatorManager, request);
  13. final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
  14. lookupCoordinatorManager,
  15. );
  16. Assert.assertEquals(202, response.getStatus());
  17. Assert.assertTrue(auditInfoCapture.hasCaptured());
  18. final AuditInfo auditInfo = auditInfoCapture.getValue();
  19. Assert.assertEquals(author, auditInfo.getAuthor());
  20. Assert.assertEquals(comment, auditInfo.getComment());
  21. Assert.assertEquals(ip, auditInfo.getIp());

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

  1. @Test
  2. public void testDeleteNetworkWithSelectedFields_Operation() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.deleteNetwork(eq(NETWORK_ID.getNetwork()), capture(capturedOptions)))
  6. .andReturn(globalOperation.toPb());
  7. EasyMock.replay(computeRpcMock);
  8. compute = options.getService();
  9. Operation operation = compute.deleteNetwork(NETWORK_ID, OPERATION_OPTION_FIELDS);
  10. String selector =
  11. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  12. assertTrue(selector.contains("selfLink"));
  13. assertTrue(selector.contains("id"));
  14. assertTrue(selector.contains("description"));
  15. assertEquals(23, selector.length());
  16. assertEquals(globalOperation, operation);
  17. }

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

  1. @Test
  2. public void testDeleteGlobalAddressWithSelectedFields_Operation() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.deleteGlobalAddress(
  6. eq(GLOBAL_ADDRESS_ID.getAddress()), capture(capturedOptions)))
  7. .andReturn(globalOperation.toPb());
  8. EasyMock.replay(computeRpcMock);
  9. compute = options.getService();
  10. Operation operation = compute.deleteAddress(GLOBAL_ADDRESS_ID, OPERATION_OPTION_FIELDS);
  11. String selector =
  12. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  13. assertTrue(selector.contains("selfLink"));
  14. assertTrue(selector.contains("id"));
  15. assertTrue(selector.contains("description"));
  16. assertEquals(23, selector.length());
  17. assertEquals(globalOperation, operation);
  18. }

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

  1. @Test
  2. public void testGetGlobalOperationWithSelectedFields() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.getGlobalOperation(
  6. eq(GLOBAL_OPERATION_ID.getOperation()), capture(capturedOptions)))
  7. .andReturn(globalOperation.toPb());
  8. EasyMock.replay(computeRpcMock);
  9. compute = options.getService();
  10. Operation operation = compute.getOperation(GLOBAL_OPERATION_ID, OPERATION_OPTION_FIELDS);
  11. String selector =
  12. (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption());
  13. assertTrue(selector.contains("selfLink"));
  14. assertTrue(selector.contains("id"));
  15. assertTrue(selector.contains("description"));
  16. assertEquals(23, selector.length());
  17. assertEquals(globalOperation, operation);
  18. }

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

  1. @Test
  2. public void testExceptionalDelete()
  3. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  4. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  5. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  6. LookupCoordinatorManager.class);
  7. EasyMock.expect(lookupCoordinatorManager.deleteLookup(
  8. EasyMock.eq(LOOKUP_TIER),
  9. EasyMock.eq(LOOKUP_NAME),
  10. EasyMock.capture(auditInfoCapture)
  11. )).andThrow(new RuntimeException(errMsg)).once();
  12. EasyMock.replay(lookupCoordinatorManager, request);
  13. );
  14. Assert.assertEquals(500, response.getStatus());
  15. Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
  16. Assert.assertTrue(auditInfoCapture.hasCaptured());
  17. final AuditInfo auditInfo = auditInfoCapture.getValue();
  18. Assert.assertEquals(author, auditInfo.getAuthor());
  19. Assert.assertEquals(comment, auditInfo.getComment());
  20. Assert.assertEquals(ip, auditInfo.getIp());

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

  1. @Test
  2. public void testSimpleDelete()
  3. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  4. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  5. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  6. LookupCoordinatorManager.class);
  7. EasyMock.expect(lookupCoordinatorManager.deleteLookup(
  8. EasyMock.eq(LOOKUP_TIER),
  9. EasyMock.eq(LOOKUP_NAME),
  10. EasyMock.capture(auditInfoCapture)
  11. )).andReturn(true).once();
  12. EasyMock.replay(lookupCoordinatorManager, request);
  13. );
  14. Assert.assertEquals(202, response.getStatus());
  15. Assert.assertTrue(auditInfoCapture.hasCaptured());
  16. final AuditInfo auditInfo = auditInfoCapture.getValue();
  17. Assert.assertEquals(author, auditInfo.getAuthor());
  18. Assert.assertEquals(comment, auditInfo.getComment());
  19. Assert.assertEquals(ip, auditInfo.getIp());

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

  1. @Test
  2. public void testGetLicenseFromStringWithOptions() {
  3. Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
  4. EasyMock.expect(
  5. computeRpcMock.getLicense(
  6. eq(PROJECT), eq(LICENSE_ID.getLicense()), capture(capturedOptions)))
  7. .andReturn(LICENSE.toPb());
  8. EasyMock.replay(computeRpcMock);
  9. compute = options.getService();
  10. License license = compute.getLicense(LICENSE_ID.getLicense(), LICENSE_OPTION_FIELDS);
  11. assertEquals(LICENSE, license);
  12. String selector = (String) capturedOptions.getValue().get(LICENSE_OPTION_FIELDS.getRpcOption());
  13. assertTrue(selector.contains("selfLink"));
  14. assertTrue(selector.contains("chargesUseFee"));
  15. assertEquals(22, selector.length());
  16. assertEquals(LICENSE, license);
  17. }

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

  1. @Test
  2. public void testGetProjectWithOptions() {
  3. EasyMock.reset(batchMock);
  4. Capture<RpcBatch.Callback<Project>> callback = Capture.newInstance();
  5. Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
  6. batchMock.addGetProject(EasyMock.capture(callback), EasyMock.capture(capturedOptions));
  7. EasyMock.replay(batchMock);
  8. DnsBatchResult<ProjectInfo> batchResult = dnsBatch.getProject(PROJECT_FIELDS);
  9. assertNotNull(callback.getValue());
  10. String selector = (String) capturedOptions.getValue().get(PROJECT_FIELDS.getRpcOption());
  11. assertTrue(selector.contains(Dns.ProjectField.QUOTA.getSelector()));
  12. assertTrue(selector.contains(Dns.ProjectField.PROJECT_ID.getSelector()));
  13. RpcBatch.Callback<Project> capturedCallback = callback.getValue();
  14. capturedCallback.onSuccess(PROJECT_INFO.toPb());
  15. assertEquals(PROJECT_INFO, batchResult.get());
  16. }

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

  1. @Test
  2. public void testDBErrNewLookup() throws Exception
  3. EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
  4. EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
  5. final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
  6. final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
  7. LookupCoordinatorManager.class);
  8. EasyMock.expect(lookupCoordinatorManager.updateLookup(
  9. EasyMock.eq(LOOKUP_TIER),
  10. EasyMock.eq(LOOKUP_NAME),
  11. EasyMock.eq(SINGLE_LOOKUP),
  12. EasyMock.capture(auditInfoCapture)
  13. )).andReturn(false).once();
  14. EasyMock.replay(lookupCoordinatorManager, request);
  15. );
  16. Assert.assertEquals(500, response.getStatus());
  17. Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
  18. Assert.assertTrue(auditInfoCapture.hasCaptured());
  19. final AuditInfo auditInfo = auditInfoCapture.getValue();
  20. Assert.assertEquals(author, auditInfo.getAuthor());
  21. Assert.assertEquals(comment, auditInfo.getComment());
  22. Assert.assertEquals(ip, auditInfo.getIp());

相关文章