本文整理汇总了Java中org.mockito.ArgumentCaptor.forClass方法的典型用法代码示例。如果您正苦于以下问题:Java ArgumentCaptor.forClass方法的具体用法?Java ArgumentCaptor.forClass怎么用?Java ArgumentCaptor.forClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mockito.ArgumentCaptor
的用法示例。
在下文中一共展示了ArgumentCaptor.forClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: complexTest1
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void complexTest1() throws Exception {
SmartLog.start(output)
.level(LogLevel.DEBUG)
.title("test-%s", "title")
.format(new SimpleTextFormat("${title} - ${result}, var=${var}, trace: [${trace}] [${time} ms]"))
.trace("trace1")
.trace("trace2")
.trace(WRITE_TIME, "trace3")
.trace("trace%d", 4)
.attach("var", "val")
.result("test-result");
SmartLog.finish();
ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
Mockito.verify(logger).debug(msgCaptor.capture());
Assertions.assertThat(msgCaptor.getValue())
.matches("test-title - test-result, var=val, trace: \\[trace1; trace2; trace3 \\[\\d+ ms\\]; trace4\\] \\[\\d+ ms\\]");
}
示例2: onClick_Shortened
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void onClick_Shortened() throws Exception {
// Given
ShortenedOnClickListener listener = mock(ShortenedOnClickListener.class);
ArgumentCaptor<View.OnClickListener> listenerCaptor = ArgumentCaptor.forClass(View.OnClickListener.class);
// When
BlueTapeDsl
.onClick(listener)
.bind(view);
verify(view).setOnClickListener(listenerCaptor.capture());
listenerCaptor.getValue().onClick(view);
// Then
verify(listener).onClick();
}
示例3: shouldProvideActionDefinition
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void shouldProvideActionDefinition() {
@SuppressWarnings({"unchecked", "rawtypes"})
final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
final ArgumentCaptor<Entity<Map<String, Object>>> entity = ArgumentCaptor.forClass(entityType);
final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName",
Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
.build();
when(invocationBuilder.post(entity.capture(), eq(DynamicActionMetadata.class))).thenReturn(suggestions);
final ConnectorDescriptor definition = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE,
Collections.emptyMap());
final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder()
.createFrom(createOrUpdateSalesforceObjectDescriptor)
.replaceConfigurationProperty("sObjectName",
c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"),
ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact")))
.build();
assertThat(definition).isEqualTo(enrichedDefinitioin);
}
示例4: shouldPassMakeRequest_toMessaging
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void shouldPassMakeRequest_toMessaging() throws ExecutionException, InterruptedException {
final CoapPacket req = newCoapPacket().get().uriPath("/test").build();
final ArgumentCaptor<Callback> callback = ArgumentCaptor.forClass(Callback.class);
//when
final CompletableFuture<CoapPacket> resp = server.makeRequest(req);
//then
verify(msg).makeRequest(eq(req), callback.capture(), eq(TransportContext.NULL));
assertFalse(resp.isDone());
//verify callback
callback.getValue().call(newCoapPacket().ack(Code.C400_BAD_REQUEST).build());
assertTrue(resp.isDone());
assertEquals(Code.C400_BAD_REQUEST, resp.get().getCode());
}
示例5: testSingleKeyValueMissing
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
/**
* Test compare value on data sets where there are missing data.
*
*/
@Test
public void testSingleKeyValueMissing() {
SelectStatement left = select(field("stringKey"), field("nullableDateCol")).from(tableRef("SingleKeyLeft"));
SelectStatement right = select(field("stringKey"), field("nullableDateCol")).from(tableRef("SingleKeyMissingRight"));
CompareCallback callBackMock = mock(CompareCallback.class);
ArgumentCaptor<ResultSetMismatch> rsMismatchCaptor = ArgumentCaptor.forClass(ResultSetMismatch.class);
int result = resultSetComparer.compare(new int[]{1}, left, right, connection, callBackMock);
verify(callBackMock, times(2)).mismatch(rsMismatchCaptor.capture());
List<ResultSetMismatch> rsMismatches = rsMismatchCaptor.getAllValues();
assertEquals("Row count should match", rsMismatches.size(), result);
checkMismatch(rsMismatches.get(0), MISSING_RIGHT, "20140101", ResultSetComparer.RECORD_NOT_PRESENT, 2, "keyA");
checkMismatch(rsMismatches.get(1), MISSING_LEFT, ResultSetComparer.RECORD_NOT_PRESENT, "20140401", 2, "keyD");
}
示例6: testGetStackPhysicalResourceId
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testGetStackPhysicalResourceId() {
final StackResource stackResource1 = new StackResource();
stackResource1.setLogicalResourceId("logical1");
stackResource1.setPhysicalResourceId("physical1");
final StackResource stackResource2 = new StackResource();
stackResource2.setLogicalResourceId("logical2");
stackResource2.setPhysicalResourceId("physical2");
final List<StackResource> stackResources = new ArrayList<>();
stackResources.add(stackResource1);
stackResources.add(stackResource2);
final DescribeStackResourcesResult result = mock(DescribeStackResourcesResult.class);
when(result.getStackResources()).thenReturn(stackResources);
when(amazonCloudFormationClient.describeStackResources(any(DescribeStackResourcesRequest.class))).thenReturn(result);
assertThat(awsHelperService.getStackPhysicalResourceId("testStackName", "logical2"), equalTo("physical2"));
final ArgumentCaptor<DescribeStackResourcesRequest> argumentCaptor = ArgumentCaptor.forClass(DescribeStackResourcesRequest.class);
verify(amazonCloudFormationClient).describeStackResources(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getStackName(), equalTo("testStackName"));
}
示例7: shouldCreateKubernetesPodWithPodLabels
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void shouldCreateKubernetesPodWithPodLabels() throws Exception {
ArgumentCaptor<Pod> argumentCaptor = ArgumentCaptor.forClass(Pod.class);
kubernetesAgentInstances.create(createAgentRequest, settings, mockedPluginRequest);
verify(pods).create(argumentCaptor.capture());
Pod elasticAgentPod = argumentCaptor.getValue();
assertNotNull(elasticAgentPod.getMetadata());
HashMap<String, String> labels = new HashMap<>();
labels.put(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID);
labels.put(Constants.JOB_ID_LABEL_KEY, createAgentRequest.jobIdentifier().getJobId().toString());
labels.put(Constants.KUBERNETES_POD_KIND_LABEL_KEY, Constants.KUBERNETES_POD_KIND_LABEL_VALUE);
labels.put(Constants.ENVIRONMENT_LABEL_KEY, createAgentRequest.environment());
assertThat(elasticAgentPod.getMetadata().getLabels(), is(labels));
}
示例8: successfulExecutionCallsResponseHandler
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void successfulExecutionCallsResponseHandler() throws Exception {
// Given
ArgumentCaptor<SdkHttpResponseHandler> sdkHttpResponseHandler = ArgumentCaptor.forClass(SdkHttpResponseHandler.class);
expectRetrievalFromMocks();
when(httpClient.prepareRequest(any(), any(), any(), sdkHttpResponseHandler.capture())).thenReturn(httpClientCall);
when(responseHandler.handle(any(), any())).thenReturn(response); // Response handler call
// When
CompletableFuture<SdkResponse> responseFuture = syncClientHandler.execute(clientExecutionParams());
sdkHttpResponseHandler.getValue().headersReceived(SdkHttpFullResponse.builder().statusCode(200).build());
sdkHttpResponseHandler.getValue().complete();
SdkResponse actualResponse = responseFuture.get(1, TimeUnit.SECONDS);
// Then
verifyNoMoreInteractions(errorResponseHandler); // No error handler calls
verify(httpClientCall).run(); // Response handler is invoked
assertThat(actualResponse).isEqualTo(response); // Response handler result returned
}
示例9: testHostResolveAttempt
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testHostResolveAttempt() throws Exception {
TaskAttemptImpl.RequestContainerTransition rct =
new TaskAttemptImpl.RequestContainerTransition(false);
EventHandler eventHandler = mock(EventHandler.class);
String[] hosts = new String[3];
hosts[0] = "192.168.1.1";
hosts[1] = "host2";
hosts[2] = "host3";
TaskSplitMetaInfo splitInfo =
new TaskSplitMetaInfo(hosts, 0, 128 * 1024 * 1024l);
TaskAttemptImpl mockTaskAttempt =
createMapTaskAttemptImplForTest(eventHandler, splitInfo);
TaskAttemptImpl spyTa = spy(mockTaskAttempt);
when(spyTa.resolveHost(hosts[0])).thenReturn("host1");
spyTa.dataLocalHosts = spyTa.resolveHosts(splitInfo.getLocations());
TaskAttemptEvent mockTAEvent = mock(TaskAttemptEvent.class);
rct.transition(spyTa, mockTAEvent);
verify(spyTa).resolveHost(hosts[0]);
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(2)).handle(arg.capture());
if (!(arg.getAllValues().get(1) instanceof ContainerRequestEvent)) {
Assert.fail("Second Event not of type ContainerRequestEvent");
}
Map<String, Boolean> expected = new HashMap<String, Boolean>();
expected.put("host1", true);
expected.put("host2", true);
expected.put("host3", true);
ContainerRequestEvent cre =
(ContainerRequestEvent) arg.getAllValues().get(1);
String[] requestedHosts = cre.getHosts();
for (String h : requestedHosts) {
expected.remove(h);
}
assertEquals(0, expected.size());
}
示例10: updateOrganizationIntern_TechProviderToSupplier
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void updateOrganizationIntern_TechProviderToSupplier()
throws Exception {
// given
final String ORG_NAME = "MyOrg";
final BigDecimal OPERATOR_REVENUE_SHARE = BigDecimal.valueOf(35);
VOOperatorOrganization org = givenOrganizationWithRoles("deadbeef",
ORG_NAME, OPERATOR_REVENUE_SHARE, OrganizationRoleType.SUPPLIER);
final Organization updatedOrg = givenOrgDomainObj("deadbeef", ORG_NAME,
null, OrganizationRoleType.TECHNOLOGY_PROVIDER);
addPaymentTypeInvoice(updatedOrg,
OrganizationReferenceType.PLATFORM_OPERATOR_TO_SUPPLIER,
OrganizationRoleType.SUPPLIER);
SupportedCountry sc = new SupportedCountry();
doReturn(updatedOrg).doReturn(sc).when(ds)
.getReferenceByBusinessKey(any(Organization.class));
mockAddOrganizationToRole(updatedOrg);
// when
VOOperatorOrganization resultOrg = opSrvBean.updateOrganizationIntern(
org, null);
// then
assertTrue("Supplier role missing", resultOrg.getOrganizationRoles()
.contains(OrganizationRoleType.SUPPLIER));
assertEquals("Wrong operator revenue share", OPERATOR_REVENUE_SHARE,
resultOrg.getOperatorRevenueShare());
ArgumentCaptor<RevenueShareModel> argRevShareModel = ArgumentCaptor
.forClass(RevenueShareModel.class);
verify(ds).persist(argRevShareModel.capture());
assertEquals("Wrong operator revenue share persisted",
OPERATOR_REVENUE_SHARE, argRevShareModel.getValue()
.getRevenueShare());
assertSame("Wrong operator price model in updated organization",
updatedOrg.getOperatorPriceModel(), argRevShareModel.getValue());
}
示例11: testAggregate
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testAggregate() throws Exception {
ArgumentCaptor<JSONObject> queueCaptor = ArgumentCaptor.forClass(JSONObject.class);
for (int i = 0; i < NUM_OF_RUNS; i++) {
commentAggregator.forwardAggregate("all");
}
Mockito.verify(queueService, times(NUM_OF_RUNS)).enqueueComment(queueCaptor.capture());
List<JSONObject> capturedModels = queueCaptor.getAllValues();
List<String> fullnames = OuputValidator.checkIncrementalIds(capturedModels);
Assert.assertTrue( OuputValidator.checkValidFullnames(fullnames)<=0);
}
示例12: checkSettings_withSslException_shouldThrowCertificateValidationException
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test(expected = CertificateValidationException.class)
public void checkSettings_withSslException_shouldThrowCertificateValidationException() throws Exception {
WebDavStore webDavStore = createDefaultWebDavStore();
ArgumentCaptor<HttpGeneric> requestCaptor = ArgumentCaptor.forClass(HttpGeneric.class);
when(mockHttpClient.executeOverride(requestCaptor.capture(), any(HttpContext.class)))
.thenThrow(new SSLException("Test"));
webDavStore.checkSettings();
}
示例13: testFireConnectEvent_noUserInteract
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testFireConnectEvent_noUserInteract() {
ArgumentCaptor<PairConnectEvent> argumentCaptor = ArgumentCaptor.forClass(PairConnectEvent.class);
for (PairConnectEventTypes type : PairConnectEventTypes.values()) {
instance.fireConnectEvent(type, SOURCE, TARGET, false);
}
verifyInteraction(argumentCaptor, false);
}
示例14: createThumbnailPassesParametersToActionService
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
/**
* This test method ensures that the parameters on thumbnail-create are
* passed through the RenditionService to the ActionService
*/
@Test
public void createThumbnailPassesParametersToActionService()
{
// As most of the services are mocked out, the actual values used here
// don't matter.
final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE, new Integer(2));
parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE, new Integer(2));
parametersUnderTest.put(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET, "00:00:00.5");
ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
imageTransOpts.setTargetNodeRef(dummyNodeRef2);
imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));
ImageResizeOptions resizeOptions = new ImageResizeOptions();
resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
imageTransOpts.setResizeOptions(resizeOptions);
PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
pagedSourceOptions.setStartPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE));
pagedSourceOptions.setEndPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE));
imageTransOpts.addSourceOptions(pagedSourceOptions);
TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
temporalSourceOptions.setOffset((String) parametersUnderTest.get(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET));
imageTransOpts.addSourceOptions(temporalSourceOptions);
ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3,
ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
"homerSimpson"));
// Now request the creation of the the thumbnail.
thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
imageTransOpts, "bartSimpson", assocDetails);
ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
final Action action = argument.getValue();
final RenditionDefinition renditionDefn = (RenditionDefinition)action;
Map<String, Serializable> parameters = renditionDefn.getParameterValues();
for (String s : parametersUnderTest.keySet())
{
if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0)
{
fail("Missing parameter " + s);
}
assertEquals("Parameter " + s + " had wrong value.",
parametersUnderTest.get(s), parameters.get(s));
}
}
示例15: testAdditionNode
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testAdditionNode() {
createAnimatedGraphWithAdditionNode(50, 100d, 1000d);
Callback animationCallback = mock(Callback.class);
JavaOnlyArray frames = JavaOnlyArray.of(0d, 1d);
mNativeAnimatedNodesManager.startAnimatingNode(
1,
1,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 101d),
animationCallback);
mNativeAnimatedNodesManager.startAnimatingNode(
2,
2,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1010d),
animationCallback);
ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
ArgumentCaptor.forClass(ReactStylesDiffMap.class);
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture());
assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1100d);
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(mUIImplementationMock)
.synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture());
assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1100d);
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(mUIImplementationMock)
.synchronouslyUpdateViewOnUIThread(eq(50), stylesCaptor.capture());
assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(1111d);
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verifyNoMoreInteractions(mUIImplementationMock);
}