public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) { List<Invocation> chunk = finder.findMatchingChunk(invocations, wanted, wantedCount, context); int actualCount = chunk.size(); if (wantedCount > actualCount) { Location lastInvocation = finder.getLastLocation(chunk); reporter.tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation); } else if (wantedCount < actualCount) { Location firstUndesired = chunk.get(wantedCount).getLocation(); reporter.tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, firstUndesired); } invocationMarker.markVerifiedInOrder(chunk, wanted, context); } }
public static void checkNumberOfInvocationsNonGreedy(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext context) { int actualCount = 0; Location lastLocation = null; while( actualCount < wantedCount ){ Invocation next = findFirstMatchingUnverifiedInvocation(invocations, wanted, context ); if( next == null ){ throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, Arrays.asList(lastLocation)); } markVerified( next, wanted ); context.markVerified( next ); lastLocation = next.getLocation(); actualCount++; } } }
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) { List<Location> allLocations = getAllLocations(chunk); throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, allLocations); } if (wantedCount < actualCount) { throw tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, getAllLocations(chunk)); } markVerifiedInOrder(chunk, wanted, context); }
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount) { List<Invocation> actualInvocations = finder.findInvocations(invocations, wanted); int actualCount = actualInvocations.size(); if (wantedCount > actualCount) { Location lastInvocation = finder.getLastLocation(actualInvocations); reporter.tooLittleActualInvocations(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation); } else if (wantedCount == 0 && actualCount > 0) { Location firstUndesired = actualInvocations.get(wantedCount).getLocation(); reporter.neverWantedButInvoked(wanted, firstUndesired); } else if (wantedCount < actualCount) { Location firstUndesired = actualInvocations.get(wantedCount).getLocation(); reporter.tooManyActualInvocations(wantedCount, actualCount, wanted, firstUndesired); } invocationMarker.markVerified(actualInvocations, wanted); } }
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) { int actualCount = 0; Location lastLocation = null; while( actualCount < wantedCount ){ Invocation next = finder.findFirstMatchingUnverifiedInvocation( invocations, wanted, context ); if( next == null ){ reporter.tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastLocation ); } marker.markVerified( next, wanted ); context.markVerified( next ); lastLocation = next.getLocation(); actualCount++; } } }
public static void checkNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount) { List<Invocation> actualInvocations = findInvocations(invocations, wanted); int actualCount = actualInvocations.size(); if (wantedCount > actualCount) { List<Location> allLocations = getAllLocations(actualInvocations); throw tooLittleActualInvocations(new Discrepancy(wantedCount, actualCount), wanted, allLocations); } if (wantedCount == 0 && actualCount > 0) { throw neverWantedButInvoked(wanted, getAllLocations(actualInvocations)); } if (wantedCount < actualCount) { throw tooManyActualInvocations(wantedCount, actualCount, wanted, getAllLocations(actualInvocations)); } markVerified(actualInvocations, wanted); }