/** * Checks that the {@code Iterable} contains the expected elements, in any order. * * <p>Returns this {@code IterableAssert}. */ @Override @SafeVarargs public final PCollectionContentsAssert<T> containsInAnyOrder(T... expectedElements) { return containsInAnyOrder(Arrays.asList(expectedElements)); }
/** * Checks that the {@code Iterable} contains elements that match the provided matchers, in any * order. * * <p>Returns this {@code IterableAssert}. */ @SafeVarargs final PCollectionContentsAssert<T> containsInAnyOrder( SerializableMatcher<? super T>... elementMatchers) { return satisfies(SerializableMatchers.containsInAnyOrder(elementMatchers)); }
@Override public IterableAssert<T> inEarlyGlobalWindowPanes() { return withPane(GlobalWindow.INSTANCE, PaneExtractors.earlyPanes()); }
@Override public PCollectionContentsAssert<T> inCombinedNonLatePanes(BoundedWindow window) { return withPane(window, PaneExtractors.nonLatePanes()); }
@Override public PCollectionContentsAssert<T> inEarlyPane(BoundedWindow window) { return withPane(window, PaneExtractors.earlyPanes()); }
@Override public PCollectionContentsAssert<T> inFinalPane(BoundedWindow window) { return withPane(window, PaneExtractors.finalPane()); }
@Override public PCollectionContentsAssert<T> inOnTimePane(BoundedWindow window) { return withPane(window, PaneExtractors.onTimePane()); }
@Override public PCollectionContentsAssert<T> inWindow(BoundedWindow window) { return withPane(window, PaneExtractors.allPanes()); }
/** * Checks that the {@code Iterable} contains the expected elements, in any order. * * <p>Returns this {@code IterableAssert}. */ @Override public PCollectionContentsAssert<T> containsInAnyOrder(Iterable<T> expectedElements) { return satisfies(new AssertContainsInAnyOrderRelation<>(), expectedElements); }
@Override public PCollectionContentsAssert<T> empty() { containsInAnyOrder(Collections.emptyList()); return this; }
private PCollectionContentsAssert<T> withPane( BoundedWindow window, SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor) { @SuppressWarnings({"unchecked", "rawtypes"}) Coder<BoundedWindow> windowCoder = (Coder) actual.getWindowingStrategy().getWindowFn().windowCoder(); return new PCollectionContentsAssert<>( actual, IntoStaticWindows.of(windowCoder, window), paneExtractor, site); }
/** * Constructs an {@link IterableAssert} for the elements of the provided {@link PCollection} with * the specified reason. */ public static <T> IterableAssert<T> that(String reason, PCollection<T> actual) { return new PCollectionContentsAssert<>(actual, PAssertionSite.capture(reason)); }
/** * Applies a {@link SerializableFunction} to check the elements of the {@code Iterable}. * * <p>Returns this {@code IterableAssert}. */ private PCollectionContentsAssert<T> satisfies( AssertRelation<Iterable<T>, Iterable<T>> relation, Iterable<T> expectedElements) { return satisfies( new CheckRelationAgainstExpected<>( relation, expectedElements, IterableCoder.of(actual.getCoder()))); }