/** * Verifies that the given {@code Iterable} starts 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 first element in the sequence is also the first 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 start with the given sequence of objects. */ public void assertStartsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, sequence)) return; int i = 0; for (Object actualCurrentElement : actual) { if (i >= sequence.length) break; if (areEqual(actualCurrentElement, sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, actual, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, actual, sequence); } }
/** * Verifies that the given {@code Iterable} starts 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 first element in the sequence is also the first 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 start with the given sequence of objects. */ public void assertStartsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, sequence)) return; int i = 0; for (Object actualCurrentElement : actual) { if (i >= sequence.length) break; if (areEqual(actualCurrentElement, sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, actual, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, actual, sequence); } }
/** * Verifies that the given {@code Iterable} starts 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 first element in the sequence is also the first 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 start with the given sequence of objects. */ public void assertStartsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) { if (commonCheckThatIterableAssertionSucceeds(info, actual, sequence)) return; int i = 0; for (Object actualCurrentElement : actual) { if (i >= sequence.length) break; if (areEqual(actualCurrentElement, sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, actual, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, actual, sequence); } }