@Override public ProxyableListAssert<ELEMENT> startsWith(@SuppressWarnings("unchecked") ELEMENT... sequence) { if (!(actual instanceof ProxyableListAssert.ListFromStream)) { return super.startsWith(sequence); } objects.assertNotNull(info, actual); checkIsNotNull(sequence); // NO SUPPORT FOR infinite streams as it prevents chaining other assertions afterward, it requires to consume the // Stream partially, if you chain another assertion, the stream is already consumed. Iterator<? extends ELEMENT> iterator = asListFromStream().stream().iterator(); if (sequence.length == 0 && iterator.hasNext()) throw new AssertionError("actual is not empty"); int i = 0; while (iterator.hasNext()) { if (i >= sequence.length) break; if (iterables.getComparisonStrategy().areEqual(iterator.next(), sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, sequence); } return myself; }
@Override public ProxyableListAssert<ELEMENT> startsWith(@SuppressWarnings("unchecked") ELEMENT... sequence) { if (!(actual instanceof ProxyableListAssert.ListFromStream)) { return super.startsWith(sequence); } objects.assertNotNull(info, actual); checkIsNotNull(sequence); // NO SUPPORT FOR infinite streams as it prevents chaining other assertions afterward, it requires to consume the // Stream partially, if you chain another assertion, the stream is already consumed. Iterator<? extends ELEMENT> iterator = asListFromStream().stream().iterator(); if (sequence.length == 0 && iterator.hasNext()) throw new AssertionError("actual is not empty"); int i = 0; while (iterator.hasNext()) { if (i >= sequence.length) break; if (iterables.getComparisonStrategy().areEqual(iterator.next(), sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, sequence); } return myself; }