/** * Verifies that the given <code>{@link Iterable}</code> contains the given subsequence of objects (possibly with * other values between them). * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param subsequence the subsequence of objects to look for. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws NullPointerException if the given sequence is {@code null}. * @throws IllegalArgumentException if the given subsequence is empty. * @throws AssertionError if the given {@code Iterable} does not contain the given subsequence of objects. */ public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, subsequence)) return; Iterator<?> actualIterator = actual.iterator(); int subsequenceIndex = 0; while (actualIterator.hasNext() && subsequenceIndex < subsequence.length) { Object actualNext = actualIterator.next(); Object subsequenceNext = subsequence[subsequenceIndex]; if (areEqual(actualNext, subsequenceNext)) subsequenceIndex++; } if (subsequenceIndex < subsequence.length) throw actualDoesNotContainSubsequence(info, actual, subsequence); }
/** * Verifies that the given <code>{@link Iterable}</code> contains the given subsequence of objects (possibly with * other values between them). * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param subsequence the subsequence of objects to look for. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws NullPointerException if the given sequence is {@code null}. * @throws IllegalArgumentException if the given subsequence is empty. * @throws AssertionError if the given {@code Iterable} does not contain the given subsequence of objects. */ public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, subsequence)) return; Iterator<?> actualIterator = actual.iterator(); int subsequenceIndex = 0; while (actualIterator.hasNext() && subsequenceIndex < subsequence.length) { Object actualNext = actualIterator.next(); Object subsequenceNext = subsequence[subsequenceIndex]; if (areEqual(actualNext, subsequenceNext)) subsequenceIndex++; } if (subsequenceIndex < subsequence.length) throw actualDoesNotContainSubsequence(info, actual, subsequence); }
/** * Verifies that the given <code>{@link Iterable}</code> contains the given subsequence of objects (possibly with * other values between them). * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param subsequence the subsequence of objects to look for. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws NullPointerException if the given sequence is {@code null}. * @throws IllegalArgumentException if the given subsequence is empty. * @throws AssertionError if the given {@code Iterable} does not contain the given subsequence of objects. */ public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, subsequence)) { return; } Iterator<?> actualIterator = actual.iterator(); int subsequenceIndex = 0; while (actualIterator.hasNext() && subsequenceIndex < subsequence.length) { Object actualNext = actualIterator.next(); Object subsequenceNext = subsequence[subsequenceIndex]; if (areEqual(actualNext, subsequenceNext)) { subsequenceIndex++; } } if (subsequenceIndex < subsequence.length) { throw actualDoesNotContainSubsequence(info, actual, subsequence); } }