@VisibleForTesting Filters(E[] array) { List<E> iterable = new ArrayList<E>(array.length); for (int i = 0; i < array.length; i++) { iterable.add(array[i]); } this.initialIterable = iterable; // copy list to avoid modifying iterable this.filteredIterable = newArrayList(iterable); }
@VisibleForTesting Filters(Iterable<E> iterable) { this.initialIterable = iterable; // copy list to avoid modifying iterable this.filteredIterable = newArrayList(iterable); }
void assertcontainsAll(AssertionInfo info, Failures failures, Object array, Iterable<?> iterable) { if (iterable == null) { throw iterableToLookForIsNull(); } assertNotNull(info, array); Object[] values = newArrayList(iterable).toArray(); Set<Object> notFound = new LinkedHashSet<Object>(); for (Object value : values) { if (!arrayContains(array, value)) { notFound.add(value); } } if (notFound.isEmpty()) { return; } throw failures.failure(info, shouldContain(array, values, notFound, comparisonStrategy)); }
/** * Asserts that the given {@code Iterable} contains all the elements of the other {@code Iterable}, in any order. * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param other the other {@code Iterable}. * @throws NullPointerException if {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} does not contain all the elements of the other * {@code Iterable}, in any order. */ public void assertContainsAll(AssertionInfo info, Iterable<?> actual, Iterable<?> other) { if (other == null) { throw iterableToLookForIsNull(); } assertNotNull(info, actual); Object[] values = newArrayList(other).toArray(); Set<Object> notFound = new LinkedHashSet<Object>(); for (Object value : values) { if (!iterableContains(actual, value)) { notFound.add(value); } } if (notFound.isEmpty()) { return; } throw failures.failure(info, shouldContain(actual, values, notFound, comparisonStrategy)); }
shouldBeLenientEqualByAccepting(actual, rejectedFieldsNames, expectedValues, newArrayList(fields)));
/** * Verifies that the actual <code>Iterable</code> is a subset of values <code>Iterable</code>. <br/> * Both actual and given iterable are treated as sets, therefore duplicates on either of them are ignored. * * @param info contains information about the assertion. * @param actual the actual {@code Iterable}. * @param values the {@code Iterable} that should contain all actual elements. * @throws AssertionError if the actual {@code Iterable} is {@code null}. * @throws NullPointerException if the given Iterable is {@code null}. * @throws AssertionError if the actual {@code Iterable} is not subset of set <code>{@link Iterable}</code> */ public void assertIsSubsetOf(AssertionInfo info, Iterable<?> actual, Iterable<?> values) { assertNotNull(info, actual); checkNotNull(info, values); List<Object> extra = newArrayList(); for (Object actualElement : actual) { if (!iterableContains(values, actualElement)) { extra.add(actualElement); } } if (extra.size() > 0) { throw actualIsNotSubsetOfSet(info, actual, values, extra); } }
shouldBeLenientEqualByIgnoring(actual, fieldsNames, expectedValues, newArrayList(fields)));
/** * Verifies that the given <code>{@link Iterable}</code> contains the given sequence of objects, without any other * objects between them. * * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param sequence the sequence 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 sequence is empty. * @throws AssertionError if the given {@code Iterable} does not contain the given sequence of objects. */ public void assertContainsSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNullAndNotEmpty(sequence); assertNotNull(info, actual); List<?> actualAsList = newArrayList(actual); for (int i = 0; i < actualAsList.size(); i++) { // look for given sequence in actual starting from current index (i) if (containsSequenceAtGivenIndex(actualAsList, sequence, i)) { return; } } throw actualDoesNotContainSequence(info, actual, sequence); }
public static List<Class<?>> collectionTypes() { return newArrayList(COLLECTION_TYPES); }
public static List<Class<?>> primitiveTypes() { return newArrayList(PRIMITIVE_TYPES); }
private static List<StackTraceElement> stackTraceInCurrentThread() { return newArrayList(Thread.currentThread().getStackTrace()); }
/** * Appends the stack trace of the current thread to the one in the given <code>{@link Throwable}</code>. * * @param t the given {@code Throwable}. * @param methodToStartFrom the name of the method used as the starting point of the current thread's stack trace. */ public static void appendStackTraceInCurentThreadToThrowable(Throwable t, String methodToStartFrom) { List<StackTraceElement> stackTrace = newArrayList(t.getStackTrace()); stackTrace.addAll(stackTraceInCurrentThread(methodToStartFrom)); t.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); }
List<StackTraceElement> filtered = newArrayList(throwable.getStackTrace()); StackTraceElement previous = null; for (StackTraceElement element : throwable.getStackTrace()) {