本文整理了Java中org.easymock.EasyMock.newCapture()
方法的一些代码示例,展示了EasyMock.newCapture()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.newCapture()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:newCapture
[英]Create a new capture instance that will keep only the last captured value.
[中]创建一个新的捕获实例,该实例将只保留最后捕获的值。
代码示例来源: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: JanusGraph/janusgraph
txConfigCapture = EasyMock.newCapture(CaptureType.ALL);
inconsistentTx = ctrl.createMock(StoreTransaction.class);
consistentTx = ctrl.createMock(StoreTransaction.class);
代码示例来源:origin: confluentinc/ksql
@Before
public void setUp() {
objectMapper = JsonMapper.INSTANCE.mapper;
ehCapture = newCapture();
drainCapture = newCapture();
limitHandlerCapture = newCapture();
final Schema schema = SchemaBuilder.struct().field("col1", Schema.OPTIONAL_STRING_SCHEMA).build();
final KafkaStreams kStreams = niceMock(KafkaStreams.class);
kStreams.setStateListener(anyObject());
expectLastCall();
expect(kStreams.state()).andReturn(State.RUNNING);
expect(queryMetadata.getRowQueue()).andReturn(rowQueue).anyTimes();
expect(queryMetadata.getResultSchema()).andReturn(schema).anyTimes();
queryMetadata.setLimitHandler(capture(limitHandlerCapture));
expectLastCall().once();
queryMetadata.setUncaughtExceptionHandler(capture(ehCapture));
expectLastCall();
replay(kStreams);
}
代码示例来源:origin: apache/incubator-druid
);
final Capture<ServiceEventBuilder<ServiceMetricEvent>> eventCapture = EasyMock.newCapture(CaptureType.ALL);
serviceEmitter.emit(EasyMock.capture(eventCapture));
EasyMock.expectLastCall().times(5);
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateJobSuccess() {
String id = "testCreateJobSuccess-id";
JobId jobId = JobId.of(id);
String query = "SELECT * in FOO";
Capture<com.google.api.services.bigquery.model.Job> jobCapture = EasyMock.newCapture();
EasyMock.expect(
bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS)))
.andReturn(newJobPb());
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
assertThat(bigquery.create(JobInfo.of(jobId, QueryJobConfiguration.of(query)))).isNotNull();
assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id);
}
代码示例来源: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: apache/incubator-druid
final CountDownLatch queryIsRegistered = new CountDownLatch(1);
Capture<ListenableFuture> capturedFuture = EasyMock.newCapture();
QueryWatcher watcher = EasyMock.createStrictMock(QueryWatcher.class);
watcher.registerQuery(
代码示例来源: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: apache/incubator-druid
Capture<Request> capturedRequest = EasyMock.newCapture();
ListenableFuture<Object> cancelledFuture = Futures.immediateCancelledFuture();
SettableFuture<Object> cancellationFuture = SettableFuture.create();
代码示例来源:origin: apache/incubator-druid
final Capture<Iterable<Cache.NamedKey>> cacheKeyCapture = EasyMock.newCapture();
EasyMock.expect(cache.getBulk(EasyMock.capture(cacheKeyCapture)))
.andReturn(ImmutableMap.of())
代码示例来源:origin: apache/incubator-druid
Capture<Request> capturedRequest = EasyMock.newCapture();
String hostName = "localhost:8080";
EasyMock.expect(
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateJobNoGet() {
String id = "testCreateJobNoGet-id";
JobId jobId = JobId.of(id);
String query = "SELECT * in FOO";
Capture<com.google.api.services.bigquery.model.Job> jobCapture = EasyMock.newCapture();
EasyMock.expect(
bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS)))
.andThrow(new BigQueryException(409, "already exists, for some reason"));
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
try {
bigquery.create(JobInfo.of(jobId, QueryJobConfiguration.of(query)));
fail("should throw");
} catch (BigQueryException e) {
assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateJobTryGet() {
final String id = "testCreateJobTryGet-id";
String query = "SELECT * in FOO";
Supplier<JobId> idProvider =
new Supplier<JobId>() {
@Override
public JobId get() {
return JobId.of(id);
}
};
Capture<com.google.api.services.bigquery.model.Job> jobCapture = EasyMock.newCapture();
EasyMock.expect(
bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS)))
.andThrow(new BigQueryException(409, "already exists, for some reason"));
EasyMock.expect(
bigqueryRpcMock.getJob(
anyString(),
EasyMock.eq(id),
EasyMock.eq((String) null),
EasyMock.eq(EMPTY_RPC_OPTIONS)))
.andReturn(newJobPb());
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
((BigQueryImpl) bigquery).create(JobInfo.of(QueryJobConfiguration.of(query)), idProvider);
assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id);
}
代码示例来源:origin: confluentinc/ksql
@Test
public void testOnSchema() throws Exception {
replayOnSubscribe();
session.getBasicRemote();
EasyMock.expectLastCall().andReturn(basic).once();
final Capture<String> schema = EasyMock.newCapture();
basic.sendText(EasyMock.capture(schema));
EasyMock.expectLastCall().andThrow(new IOException("bad bad io")).once();
final Capture<CloseReason> reason = EasyMock.newCapture();
session.close(EasyMock.capture(reason));
subscription.cancel();
EasyMock.replay(subscription, session, basic);
subscriber.onSchema(SchemaBuilder
.struct()
.field("currency", Schema.STRING_SCHEMA)
.field("amount", Schema.OPTIONAL_FLOAT32_SCHEMA)
.build());
subscriber.close();
assertEquals(
"[" +
"{\"name\":\"currency\"," +
"\"schema\":{\"type\":\"STRING\",\"fields\":null,\"memberSchema\":null}}," +
"{\"name\":\"amount\"," +
"\"schema\":{\"type\":\"DOUBLE\",\"fields\":null,\"memberSchema\":null}}]"
, schema.getValue());
assertEquals("Unable to send schema", reason.getValue().getReasonPhrase());
assertEquals(CloseCodes.PROTOCOL_ERROR, reason.getValue().getCloseCode());
EasyMock.verify(subscription, session, basic);
}
代码示例来源:origin: apache/incubator-druid
Capture<Request> capturedRequest = EasyMock.newCapture();
EasyMock.expect(
httpClient.go(
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderOnRequests(final String headerName) throws Exception {
final String headerValue = HttpTestUtils.getCanonicalHeaderValue(request, headerName);
final Capture<ClassicHttpRequest> cap = EasyMock.newCapture();
EasyMock.expect(
mockExecChain.proceed(
EasyMock.capture(cap),
EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
replayMocks();
execute(request);
verifyMocks();
assertEquals(headerValue,
HttpTestUtils.getCanonicalHeaderValue(cap.getValue(),
headerName));
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testDoesNotAddAMaxForwardsHeaderToForwardedOPTIONSRequests() throws Exception {
request = new BasicClassicHttpRequest("OPTIONS", "/");
final Capture<ClassicHttpRequest> reqCap = EasyMock.newCapture();
EasyMock.expect(
mockExecChain.proceed(
EasyMock.capture(reqCap),
EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
replayMocks();
execute(request);
verifyMocks();
final ClassicHttpRequest forwarded = reqCap.getValue();
Assert.assertNull(forwarded.getFirstHeader("Max-Forwards"));
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testProperlyFormattedViaHeaderIsAddedToRequests() throws Exception {
final Capture<ClassicHttpRequest> cap = EasyMock.newCapture();
request.removeHeaders("Via");
EasyMock.expect(
mockExecChain.proceed(
EasyMock.capture(cap),
EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
replayMocks();
execute(request);
verifyMocks();
final ClassicHttpRequest captured = cap.getValue();
final String via = captured.getFirstHeader("Via").getValue();
assertValidViaHeader(via);
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testDecrementsMaxForwardsWhenForwardingOPTIONSRequest() throws Exception {
request = new BasicClassicHttpRequest("OPTIONS", "*");
request.setHeader("Max-Forwards", "7");
final Capture<ClassicHttpRequest> cap = EasyMock.newCapture();
EasyMock.expect(
mockExecChain.proceed(
EasyMock.capture(cap),
EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
replayMocks();
execute(request);
verifyMocks();
final ClassicHttpRequest captured = cap.getValue();
Assert.assertEquals("6", captured.getFirstHeader("Max-Forwards").getValue());
}
代码示例来源:origin: apache/httpcomponents-client
private void testDoesNotModifyHeaderOnRequest(final String header, final String value) throws Exception {
final BasicClassicHttpRequest req = new BasicClassicHttpRequest("POST","/");
req.setEntity(HttpTestUtils.makeBody(128));
req.setHeader("Content-Length","128");
req.setHeader(header,value);
final Capture<ClassicHttpRequest> cap = EasyMock.newCapture();
EasyMock.expect(
mockExecChain.proceed(
EasyMock.capture(cap),
EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
replayMocks();
execute(req);
verifyMocks();
final ClassicHttpRequest captured = cap.getValue();
Assert.assertEquals(value, captured.getFirstHeader(header).getValue());
}
内容来源于网络,如有侵权,请联系作者删除!