static void checkIsNotNullAndNotEmpty(Iterable<?> iterable) { checkIsNotNull(iterable); checkIsNotEmpty(iterable); }
static void checkIsNotNullAndNotEmpty(Object[] values) { checkIsNotNull(values); checkIsNotEmpty(values); }
public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, List<?> subsequence) { checkIsNotNull(subsequence); assertContainsSubsequence(info, actual, subsequence.toArray()); }
private void checkNotNullIterables(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); }
public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, List<?> subsequence) { checkIsNotNull(subsequence); assertContainsSubsequence(info, actual, subsequence.toArray()); }
static void checkIsNotNullAndNotEmpty(Object[] values) { checkIsNotNull(values); checkIsNotEmpty(values); }
static void checkIsNotNullAndNotEmpty(Iterable<?> iterable) { checkIsNotNull(iterable); checkIsNotEmpty(iterable); }
private void checkNotNullIterables(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); }
@Override @SafeVarargs public final IterableAssert<ELEMENT> startsWith(ELEMENT... sequence) { if (!(actual instanceof LazyIterable)) { return super.startsWith(sequence); } objects.assertNotNull(info, actual); checkIsNotNull(sequence); // To handle infinite iterator we use the internal iterator instead of iterator() that consumes it totally. @SuppressWarnings({ "rawtypes" }) Iterator<? extends ELEMENT> iterator = ((LazyIterable) actual).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, actual, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, actual, sequence); } return myself; }
@Override @SafeVarargs public final ListAssert<ELEMENT> startsWith(ELEMENT... sequence) { if (!(actual instanceof 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; }
@Override @SafeVarargs public final ListAssert<ELEMENT> startsWith(ELEMENT... sequence) { if (!(actual instanceof 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; }
public void assertContainsExactlyInAnyOrder(AssertionInfo info, Iterable<?> actual, Object[] values) { checkIsNotNull(values); assertNotNull(info, actual); List<Object> notExpected = newArrayList(actual); List<Object> notFound = newArrayList(values); for (Object value : values) { if (iterableContains(notExpected, value)) { iterablesRemoveFirst(notExpected, value); iterablesRemoveFirst(notFound, value); } } if (notExpected.isEmpty() && notFound.isEmpty()) return; throw failures.failure(info, shouldContainExactlyInAnyOrder(actual, values, notFound, notExpected, comparisonStrategy)); }
@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; }
public void assertContainsExactlyInAnyOrder(AssertionInfo info, Iterable<?> actual, Object[] values) { checkIsNotNull(values); assertNotNull(info, actual); List<Object> notExpected = newArrayList(actual); List<Object> notFound = newArrayList(values); for (Object value : values) { if (iterableContains(notExpected, value)) { iterablesRemoveFirst(notExpected, value); iterablesRemoveFirst(notFound, value); } } if (notExpected.isEmpty() && notFound.isEmpty()) return; throw failures.failure(info, shouldContainExactlyInAnyOrder(actual, values, notFound, notExpected, comparisonStrategy)); }
private boolean commonCheckThatLogFileAssertionSucceeds(AssertionInfo info, File actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); files.assertIsFile(info, actual); files.assertExists(info, actual); // if both actual and values are empty, then assertion passes. if (FileUtils.sizeOf(actual) == 0 && sequence.length == 0) { return true; } failIfEmptySinceActualIsNotEmpty(sequence); return false; }
checkIsNotNull(values); assertNotNull(info, actual);
checkIsNotNull(values); assertNotNull(info, actual);
static void checkIsNotNullAndNotEmpty(Object[] values) { checkIsNotNull(values); checkIsNotEmpty(values); }
private boolean commonCheckThatIterableAssertionSucceeds(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); // if both actual and values are empty, then assertion passes. if (!actual.iterator().hasNext() && sequence.length == 0) return true; failIfEmptySinceActualIsNotEmpty(sequence); return false; }