/** * Verifies that the given {@code Iterable} ends with the given sequence of objects, without any other objects between * them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it also * verifies that the last element in the sequence is also the last element of the given {@code Iterable}. * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param sequence the sequence of objects to look for. * @throws NullPointerException if the given argument is {@code null}. * @throws IllegalArgumentException if the given argument is an empty array. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} does not end with the given sequence of objects. */ public void assertEndsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkNotNullIterables(info, actual, sequence); int sizeOfActual = sizeOf(actual); if (sizeOfActual < sequence.length) throw actualDoesNotEndWithSequence(info, actual, sequence); int start = sizeOfActual - sequence.length; int sequenceIndex = 0, indexOfActual = 0; for (Object actualElement : actual) { if (indexOfActual++ < start) continue; if (areEqual(actualElement, sequence[sequenceIndex++])) continue; throw actualDoesNotEndWithSequence(info, actual, sequence); } }
/** * Verifies that the given {@code Iterable} ends with the given sequence of objects, without any other objects between * them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it also * verifies that the last element in the sequence is also the last element of the given {@code Iterable}. * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param sequence the sequence of objects to look for. * @throws NullPointerException if the given argument is {@code null}. * @throws IllegalArgumentException if the given argument is an empty array. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} does not end with the given sequence of objects. */ public void assertEndsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkNotNullIterables(info, actual, sequence); int sizeOfActual = sizeOf(actual); if (sizeOfActual < sequence.length) throw actualDoesNotEndWithSequence(info, actual, sequence); int start = sizeOfActual - sequence.length; int sequenceIndex = 0, indexOfActual = 0; for (Object actualElement : actual) { if (indexOfActual++ < start) continue; if (areEqual(actualElement, sequence[sequenceIndex++])) continue; throw actualDoesNotEndWithSequence(info, actual, sequence); } }
/** * Verifies that the given {@code Iterable} ends with the given sequence of objects, without any other objects between * them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it also * verifies that the last element in the sequence is also the last element of the given {@code Iterable}. * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param sequence the sequence of objects to look for. * @throws NullPointerException if the given argument is {@code null}. * @throws IllegalArgumentException if the given argument is an empty array. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} does not end with the given sequence of objects. */ public void assertEndsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, sequence)) return; int sizeOfActual = sizeOf(actual); if (sizeOfActual < sequence.length) { throw actualDoesNotEndWithSequence(info, actual, sequence); } int start = sizeOfActual - sequence.length; int sequenceIndex = 0, indexOfActual = 0; for (Object actualElement : actual) { if (indexOfActual++ < start) continue; if (areEqual(actualElement, sequence[sequenceIndex++])) continue; throw actualDoesNotEndWithSequence(info, actual, sequence); } }