本文整理汇总了Java中org.mockito.ArgumentCaptor.getAllValues方法的典型用法代码示例。如果您正苦于以下问题:Java ArgumentCaptor.getAllValues方法的具体用法?Java ArgumentCaptor.getAllValues怎么用?Java ArgumentCaptor.getAllValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mockito.ArgumentCaptor
的用法示例。
在下文中一共展示了ArgumentCaptor.getAllValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkSettings_withOkResponse_shouldPerformFormBasedAuthentication
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void checkSettings_withOkResponse_shouldPerformFormBasedAuthentication() throws Exception {
WebDavStore webDavStore = createDefaultWebDavStore();
ArgumentCaptor<HttpGeneric> requestCaptor = ArgumentCaptor.forClass(HttpGeneric.class);
when(mockHttpClient.executeOverride(requestCaptor.capture(), any(HttpContext.class)))
.thenReturn(OK_200_RESPONSE)
.thenReturn(createOkResponseWithForm())
.thenAnswer(createOkResponseWithCookie())
.thenReturn(OK_200_RESPONSE);
webDavStore.checkSettings();
List<HttpGeneric> requests = requestCaptor.getAllValues();
assertEquals(4, requests.size());
assertEquals("GET", requests.get(0).getMethod()); // Checking auth type
assertEquals("POST", requests.get(1).getMethod()); // Posting form data
assertEquals("http://example.org:80/exchweb/bin/auth/owaauth.dll", requests.get(1).getURI().toString());
assertEquals("POST", requests.get(2).getMethod()); // Confirming login
assertEquals("http://example.org:80/exchweb/bin/auth/owaauth.dll", requests.get(2).getURI().toString());
assertEquals("GET", requests.get(3).getMethod()); // Getting response
}
示例2: testCreate
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testCreate() {
Task task = new Task();
task.setId(13L);
task.setName("myTask");
taskRepo.create(task);
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:post:/tasks/13/", repositorySpan.name());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertTag(repositorySpan, "lc", "crnk");
assertTag(repositorySpan, "crnk.query", "?");
}
示例3: willLogBeforeAndAfter
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
void willLogBeforeAndAfter() throws Exception {
Method testMethod =
WatcherExtensionTest.class.getMethod("canExecuteATestWithTheWatcherEngaged");
givenExtensionContentWithMethod(testMethod);
when(store.remove(eq(testMethod), eq(long.class))).thenReturn(System.currentTimeMillis());
sut.beforeTestExecution(extensionContext);
sut.afterTestExecution(extensionContext);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(2)).info(captor.capture());
List<String> logEvents = captor.getAllValues();
assertThat(logEvents.size(), is(2));
assertThat(logEvents.get(0), is(String.format("Starting test [%s]", testMethod.getName())));
assertThat(
logEvents.get(1),
startsWith(String.format("Completed test [%s] in ", testMethod.getName())));
}
示例4: shouldProcessManyImageActions
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void shouldProcessManyImageActions() {
// given
List<FeedbackAction> actions = ActionListBuilder.create().addUrlAction(ActionType.NARRATION, "good.mp3").addUrlAction(ActionType.IMAGE, "good.jpg")
.addUrlAction(ActionType.NARRATION, "allok.mp3").addUrlAction(ActionType.IMAGE, "bad.jpg").getList();
initializeWithActions(actions);
initializeModuleHierarchyWithImageProcessor();
// when
processor.processActions(source);
// then
ArgumentCaptor<FeedbackAction> argument = ArgumentCaptor.forClass(FeedbackAction.class);
verify(imageProcessor, times(2)).processSingleAction(argument.capture(), eq(FeedbackMark.OK));
assertThat(collector.getActions().size(), is(equalTo(0)));
List<FeedbackAction> processedActions = argument.getAllValues();
FeedbackAction processedAction1 = processedActions.get(0);
assertThat(processedAction1, is(instanceOf(ShowUrlAction.class)));
assertThat(((ShowUrlAction) processedAction1).getHref(), is(equalTo("good.jpg")));
FeedbackAction processedAction2 = processedActions.get(1);
assertThat(processedAction2, is(instanceOf(ShowUrlAction.class)));
assertThat(((ShowUrlAction) processedAction2).getHref(), is(equalTo("bad.jpg")));
}
示例5: shareItem
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void shareItem() throws Exception {
final long pathParam_itemId = ITEM_ID1;
final Resource authenticatedResource = Resources.getInstance(22L);
when(oacc.getSessionResource()).thenReturn(authenticatedResource);
todoItemService.shareItem(oacc,
pathParam_itemId,
EMAIL);
ArgumentCaptor<ResourcePermission> permissionCaptor = ArgumentCaptor.forClass(ResourcePermission.class);
ArgumentCaptor<ResourcePermission> permissionVarargsCaptor = ArgumentCaptor.forClass(ResourcePermission.class);
verify(oacc).grantResourcePermissions(eq(Resources.getInstance(EMAIL)),
eq(Resources.getInstance(String.valueOf(pathParam_itemId))),
permissionCaptor.capture(),
permissionVarargsCaptor.capture());
final List<ResourcePermission> permissions = permissionVarargsCaptor.getAllValues();
permissions.add(permissionCaptor.getValue());
assertThat(permissions).containsExactlyInAnyOrder(SecurityModel.PERM_MARK_COMPLETED, SecurityModel.PERM_VIEW);
verify(oacc, never()).assertResourcePermissions(any(Resource.class),
any(Resource.class),
any());
verifyZeroInteractions(todoItemDAO);
}
示例6: captureStepOutput
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
private StepOutput captureStepOutput() {
StepOutput actualOutput = new StepOutput();
ArgumentCaptor<CloudServiceBrokerExtended> createArgumentCaptor = ArgumentCaptor.forClass(CloudServiceBrokerExtended.class);
int expectedCreatedBrokersCnt = expectedOutput.createdServiceBrokers.size();
Mockito.verify(serviceBrokerCreator, Mockito.times(expectedCreatedBrokersCnt)).createServiceBroker(Mockito.eq(client),
createArgumentCaptor.capture());
actualOutput.createdServiceBrokers = createArgumentCaptor.getAllValues();
ArgumentCaptor<CloudServiceBrokerExtended> updateArgumentCaptor = ArgumentCaptor.forClass(CloudServiceBrokerExtended.class);
int expectedUpdatedBrokersCnt = expectedOutput.updatedServiceBrokers.size();
Mockito.verify(client, Mockito.times(expectedUpdatedBrokersCnt)).updateServiceBroker(updateArgumentCaptor.capture());
actualOutput.updatedServiceBrokers = updateArgumentCaptor.getAllValues();
return actualOutput;
}
示例7: testError
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testError() {
Task task = new Task();
task.setId(13L);
try {
taskRepo.create(task);
}
catch (Exception e) {
// ok
}
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(isOkHttp ? 2 : 1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.name);
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
assertBinaryAnnotation(callSpan, "http.status_code", "500");
if (isOkHttp) {
Span linkSpan = clientSpans.get(1);
Assert.assertEquals("post", linkSpan.name);
Assert.assertTrue(linkSpan.toString().contains("\"lc\""));
}
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan = serverSpans.get(0);
Assert.assertEquals("crnk:post:/tasks/13", repositorySpan.name);
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?");
assertBinaryAnnotation(repositorySpan, "crnk.status", "EXCEPTION");
}
示例8: testError
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testError() {
Task task = new Task();
task.setId(13L);
try {
taskRepo.create(task);
}
catch (Exception e) {
// ok
}
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("post", callSpan.getName());
Assert.assertTrue(callSpan.toString().contains("\"cs\""));
Assert.assertTrue(callSpan.toString().contains("\"cr\""));
assertBinaryAnnotation(callSpan, "http.status_code", "500");
// check server local span
Assert.assertEquals(1, reportedSpans.spans.size());
Span repositorySpan = reportedSpans.spans.get(0);
Assert.assertEquals("crnk:post:/tasks/13", repositorySpan.getName());
Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
assertBinaryAnnotation(repositorySpan, "lc", "crnk");
assertBinaryAnnotation(repositorySpan, "crnk.query", "?");
assertBinaryAnnotation(repositorySpan, "crnk.status", "EXCEPTION");
}
示例9: verifyListenerOnHit
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
private void verifyListenerOnHit(CacheKey key, String resourceId) {
ArgumentCaptor<CacheEvent> cacheEventCaptor = ArgumentCaptor.forClass(CacheEvent.class);
mCacheEventListenerInOrder.verify(mCacheEventListener).onHit(cacheEventCaptor.capture());
for (CacheEvent event : cacheEventCaptor.getAllValues()) {
CacheEventAssert.assertThat(event)
.isNotNull()
.hasCacheKey(key)
.hasResourceId(resourceId);
}
}
示例10: on
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
public List<JavaClass> on(Class<?>... toCheck) {
JavaClasses classes = importClassesWithContext(toCheck);
ArchCondition<JavaClass> condition = spy(new ArchCondition<JavaClass>("ignored") {
@Override
public void check(JavaClass item, ConditionEvents events) {
}
});
givenClasses.should(condition).check(classes);
ArgumentCaptor<JavaClass> classesCaptor = ArgumentCaptor.forClass(JavaClass.class);
verify(condition, atLeast(0)).check(classesCaptor.capture(), any(ConditionEvents.class));
return classesCaptor.getAllValues();
}
示例11: testTodo
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testTodo() {
MainScreen mainScreen = mock(MainScreen.class);
mianPresenter.attachScreen(mainScreen);
mianPresenter.getFavourites();
ArgumentCaptor<String> todosCaptor = ArgumentCaptor.forClass(String.class);
verify(mainScreen, times(2)).showMessage(todosCaptor.capture());
List<String> capturedTodos = todosCaptor.getAllValues();
assertEquals("todo one", capturedTodos.get(0));
assertEquals("todo two", capturedTodos.get(1));
}
示例12: testFindTargets
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@Test
public void testFindTargets() {
RelationshipRepositoryV2<Project, Serializable, Task, Serializable> relRepo = client
.getRepositoryForType(Project.class, Task.class);
relRepo.findManyTargets(123L, "tasks", new QuerySpec(Task.class));
// check client call and link span
ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
List<Span> clientSpans = clientSpanCaptor.getAllValues();
Span callSpan = clientSpans.get(0);
Assert.assertEquals("get", callSpan.name());
Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
// check server local span
ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
Mockito.verify(serverReporter, Mockito.times(2)).report(serverSpanCaptor.capture());
List<Span> serverSpans = serverSpanCaptor.getAllValues();
Span repositorySpan0 = serverSpans.get(0);
Assert.assertEquals("crnk:get:/tasks/", repositorySpan0.name());
Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
assertTag(repositorySpan0, "lc", "crnk");
assertTag(repositorySpan0, "crnk.results", "0");
assertTag(repositorySpan0, "crnk.status", "OK");
Span repositorySpan1 = serverSpans.get(1);
Assert.assertEquals("crnk:get:/projects/123/tasks/", repositorySpan1.name());
Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
assertTag(repositorySpan1, "lc", "crnk");
assertTag(repositorySpan1, "crnk.query", "?");
assertTag(repositorySpan1, "crnk.results", "0");
assertTag(repositorySpan1, "crnk.status", "OK");
}
示例13: getCallArgumentsOfUpdateApplicationEnvMethod
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<CloudApplication> getCallArgumentsOfUpdateApplicationEnvMethod(CloudSpace space, CloudFoundryOperations client) {
ArgumentCaptor<Map> appEnvCaptor = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<String> appNameCaptor = ArgumentCaptor.forClass(String.class);
verify(client, Mockito.atLeast(0)).updateApplicationEnv(appNameCaptor.capture(), appEnvCaptor.capture());
List<Map> appEnvs = appEnvCaptor.getAllValues();
List<String> appNames = appNameCaptor.getAllValues();
List<CloudApplication> result = new ArrayList<>();
for (int i = 0; i < appNames.size(); i++) {
result.add(createApp(appNames.get(i), space, appEnvs.get(i)));
}
return result;
}
示例14: captureStepOutput
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
private StepOutput captureStepOutput() throws Exception {
ArgumentCaptor<ConfigurationSubscription> argumentCaptor;
StepOutput output = new StepOutput();
argumentCaptor = ArgumentCaptor.forClass(ConfigurationSubscription.class);
Mockito.verify(dao, times(input.subscriptionsToUpdate.size())).update(eq(DUMMY_ID), argumentCaptor.capture());
output.updatedSubscriptions = argumentCaptor.getAllValues();
argumentCaptor = ArgumentCaptor.forClass(ConfigurationSubscription.class);
Mockito.verify(dao, times(input.subscriptionsToCreate.size())).add(argumentCaptor.capture());
output.createdSubscriptions = argumentCaptor.getAllValues();
return output;
}
示例15: filterCaptured
import org.mockito.ArgumentCaptor; //导入方法依赖的package包/类
protected <T> List<T> filterCaptured(final ArgumentCaptor<T> captor, final Class<T> type) {
List<T> captured = new ArrayList<>();
for (T c: captor.getAllValues()) {
if (type.isInstance(c)) {
captured.add(c);
}
}
return captured;
}