use of org.mockito.ArgumentCaptor in project AuthMeReloaded by AuthMe.
the class HasPermissionCheckerTest method shouldShowUsageInfo.
@Test
public void shouldShowUsageInfo() {
// given
CommandSender sender = mock(CommandSender.class);
// when
hasPermissionChecker.execute(sender, emptyList());
// then
ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
verify(sender, atLeast(2)).sendMessage(msgCaptor.capture());
assertThat(msgCaptor.getAllValues().stream().anyMatch(msg -> msg.contains("/authme debug perm bobby my.perm.node")), equalTo(true));
}
use of org.mockito.ArgumentCaptor in project beam by apache.
the class FirestoreV1FnRunQueryTest method resumeFromLastReadValue.
@Override
public void resumeFromLastReadValue() throws Exception {
TestData testData = TestData.fieldEqualsBar().setProjectId(projectId).setOrderFunction(f -> Collections.singletonList(Order.newBuilder().setDirection(Direction.ASCENDING).setField(f).build())).build();
RunQueryRequest request2 = RunQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).setStructuredQuery(testData.request.getStructuredQuery().toBuilder().setStartAt(Cursor.newBuilder().setBefore(false).addValues(Value.newBuilder().setStringValue("bar")))).build();
List<RunQueryResponse> responses = ImmutableList.of(testData.response1, testData.response2, testData.response3);
when(responseStream1.iterator()).thenReturn(new AbstractIterator<RunQueryResponse>() {
private int invocationCount = 1;
@Override
protected RunQueryResponse computeNext() {
int count = invocationCount++;
if (count == 1) {
return responses.get(0);
} else if (count == 2) {
return responses.get(1);
} else {
throw RETRYABLE_ERROR;
}
}
});
when(callable.call(testData.request)).thenReturn(responseStream1);
doNothing().when(attempt).checkCanRetry(any(), eq(RETRYABLE_ERROR));
when(responseStream2.iterator()).thenReturn(ImmutableList.of(responses.get(2)).iterator());
when(callable.call(request2)).thenReturn(responseStream2);
when(stub.runQueryCallable()).thenReturn(callable);
when(ff.getFirestoreStub(any())).thenReturn(stub);
when(ff.getRpcQos(any())).thenReturn(rpcQos);
when(rpcQos.newReadAttempt(any())).thenReturn(attempt);
when(attempt.awaitSafeToProceed(any())).thenReturn(true);
ArgumentCaptor<RunQueryResponse> responsesCaptor = ArgumentCaptor.forClass(RunQueryResponse.class);
doNothing().when(processContext).output(responsesCaptor.capture());
when(processContext.element()).thenReturn(testData.request);
RunQueryFn fn = new RunQueryFn(clock, ff, rpcQosOptions);
runFunction(fn);
List<RunQueryResponse> allValues = responsesCaptor.getAllValues();
assertEquals(responses, allValues);
verify(callable, times(1)).call(testData.request);
verify(callable, times(1)).call(request2);
verify(attempt, times(3)).recordStreamValue(any());
}
use of org.mockito.ArgumentCaptor in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(1, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(1, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2);
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(newArrayList(HIT_SOURCE));
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).scroll(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
use of org.mockito.ArgumentCaptor in project powermock by powermock.
the class AnnotationEnabler method processAnnotationOn.
private Object processAnnotationOn(Captor annotation, Field field) {
Class<?> type = field.getType();
if (!ArgumentCaptor.class.isAssignableFrom(type)) {
throw new MockitoException("@Captor field must be of the type ArgumentCaptor.\n" + "Field: '" + field.getName() + "' has wrong type\n" + "For info how to use @Captor annotations see examples in javadoc for MockitoAnnotations class.");
}
Class cls = new GenericMaster().getGenericType(field);
return ArgumentCaptor.forClass(cls);
}
use of org.mockito.ArgumentCaptor in project stashbot by palantir.
the class MockGitCommandBuilderFactory method reset.
@SuppressWarnings("unchecked")
private void reset() {
// list of changesets in order
changesets = new ArrayList<String>();
blacklistedChangesets = new HashSet<String>();
// for each hash, list of branches that contain said hash
branchMap = new HashMap<String, List<String>>();
gcbf = Mockito.mock(GitCommandBuilderFactory.class);
grlb = Mockito.mock(GitRevListBuilder.class);
gscb = Mockito.mock(GitScmCommandBuilder.class);
branchCommandBuilder = Mockito.mock(GitScmCommandBuilder.class);
cmd = Mockito.mock(GitCommand.class);
branchCommand = Mockito.mock(GitCommand.class);
// RevList cmd
Mockito.when(gcbf.builder()).thenReturn(gscb);
Mockito.when(gcbf.builder(Mockito.any(Repository.class))).thenReturn(gscb);
Mockito.when(gscb.revList()).thenReturn(grlb);
final ArgumentCaptor<CommandOutputHandler<Object>> cohCaptor = (ArgumentCaptor<CommandOutputHandler<Object>>) (Object) ArgumentCaptor.forClass(CommandOutputHandler.class);
Mockito.when(grlb.build(cohCaptor.capture())).thenReturn(cmd);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CommandOutputHandler<Object> coh = cohCaptor.getValue();
List<String> finalCS = new ArrayList<String>();
for (String cs : changesets) {
if (!blacklistedChangesets.contains(cs)) {
finalCS.add(cs);
}
}
String str = StringUtils.join(finalCS, "\n") + "\n";
InputStream is = new ByteArrayInputStream(str.getBytes());
coh.process(is);
return null;
}
}).when(cmd).call();
// Branch cmd - returns list of all branches
final ArgumentCaptor<CommandOutputHandler<Object>> branchCOHCaptor = (ArgumentCaptor<CommandOutputHandler<Object>>) (Object) ArgumentCaptor.forClass(CommandOutputHandler.class);
Mockito.when(gscb.command("branch")).thenReturn(branchCommandBuilder);
Mockito.when(branchCommandBuilder.build(branchCOHCaptor.capture())).thenReturn(branchCommand);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CommandOutputHandler<Object> coh = branchCOHCaptor.getValue();
String output = "";
List<String> branches = new ArrayList<String>(branchMap.keySet());
for (String branch : branches) {
output = output + " " + branch + "\n";
}
InputStream is = new ByteArrayInputStream(output.getBytes());
coh.process(is);
return null;
}
}).when(branchCommand).call();
}
Aggregations