use of org.mockito.invocation.Invocation in project mockito by mockito.
the class NumberOfInvocationsChecker method checkNumberOfInvocations.
public static void checkNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext context) {
List<Invocation> chunk = findMatchingChunk(invocations, wanted, wantedCount, context);
int actualCount = chunk.size();
if (wantedCount > actualCount) {
Location lastInvocation = getLastLocation(chunk);
throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation);
}
if (wantedCount < actualCount) {
Location firstUndesired = chunk.get(wantedCount).getLocation();
throw tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, firstUndesired);
}
markVerifiedInOrder(chunk, wanted, context);
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationMarkerTest method shouldMarkInvocationsAsVerifiedInOrder.
@Test
public void shouldMarkInvocationsAsVerifiedInOrder() {
//given
InOrderContextImpl context = new InOrderContextImpl();
Invocation i = new InvocationBuilder().toInvocation();
InvocationMatcher im = new InvocationBuilder().toInvocationMatcher();
assertFalse(context.isVerified(i));
assertFalse(i.isVerified());
//when
InvocationMarker.markVerifiedInOrder(Arrays.asList(i), im, context);
//then
assertTrue(context.isVerified(i));
assertTrue(i.isVerified());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationMarkerTest method shouldCaptureArguments.
@Test
public void shouldCaptureArguments() {
//given
Invocation i = new InvocationBuilder().toInvocation();
final AtomicReference<Invocation> box = new AtomicReference<Invocation>();
MatchableInvocation c = new InvocationMatcher(i) {
public void captureArgumentsFrom(Invocation i) {
box.set(i);
}
};
//when
InvocationMarker.markVerified(Arrays.asList(i), c);
//then
assertEquals(i, box.get());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationMatcherTest method should_capture_arguments_from_invocation.
@Test
public void should_capture_arguments_from_invocation() throws Exception {
//given
Invocation invocation = new InvocationBuilder().args("1", 100).toInvocation();
CapturingMatcher capturingMatcher = new CapturingMatcher();
InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new Equals("1"), capturingMatcher));
//when
invocationMatcher.captureArgumentsFrom(invocation);
//then
assertEquals(1, capturingMatcher.getAllValues().size());
assertEquals(100, capturingMatcher.getLastValue());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationMatcherTest method should_know_if_is_similar_to.
@Test
public void should_know_if_is_similar_to() throws Exception {
Invocation same = new InvocationBuilder().mock(mock).simpleMethod().toInvocation();
assertTrue(simpleMethod.hasSimilarMethod(same));
Invocation different = new InvocationBuilder().mock(mock).differentMethod().toInvocation();
assertFalse(simpleMethod.hasSimilarMethod(different));
}
Aggregations