/** A {@link SerializableMatcher} that matches any {@link KV} with matching key and value. */ public static <K, V> SerializableMatcher<KV<? extends K, ? extends V>> kv( final SerializableMatcher<? super K> keyMatcher, final SerializableMatcher<? super V> valueMatcher) { return SerializableMatchers.allOf( SerializableMatchers.kvWithKey(keyMatcher), SerializableMatchers.kvWithValue(valueMatcher)); }
/** * 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)); }
/** A {@link SerializableMatcher} that matches any {@link KV} with the specified value. */ public static <K, V extends Serializable> SerializableMatcher<KV<? extends K, ? extends V>> kvWithValue(V value) { return new KvValueMatcher<>(equalTo(value)); }
/** A {@link SerializableMatcher} with identical criteria to {@link Matchers#emptyArray()}. */ public static <T> SerializableMatcher<T[]> emptyArray() { return fromSupplier(Matchers::emptyArray); }
@Test public void testKvMatcherGBKLikeSuccess() throws Exception { assertThat( KV.of("key", ImmutableList.of(1, 2, 3)), SerializableMatchers.<Object, Iterable<Integer>>kv( anything(), containsInAnyOrder(3, 2, 1))); }
@Test public void testKvKeyMatcherSerializable() throws Exception { assertThat(KV.of("hello", 42L), SerializableUtils.ensureSerializable(kvWithKey("hello"))); }
SerializableMatchers.allOf( new FileChecksumMatcher( VALUE_CHECKSUM, new FilePatternMatchingShardedFile(singleOutputPrefix + "*")),
@Test public void testAnythingSerializable() throws Exception { SerializableUtils.ensureSerializable(anything()); }
@Test public void testAssertionSiteIsCaptured() { // This check should return a failure. SuccessOrFailure res = PAssert.doChecks( PAssert.PAssertionSite.capture("Captured assertion message."), 10, new MatcherCheckerFn(SerializableMatchers.contains(11))); String stacktrace = Throwables.getStackTraceAsString(res.assertionError()); assertEquals(false, res.isSuccess()); assertThat(stacktrace, containsString("PAssertionSite.capture")); }
/** A {@link SerializableMatcher} with identical criteria to {@link Matchers#nullValue}. */ public static SerializableMatcher<Object> nullValue() { return fromSupplier(Matchers::nullValue); }
@Test public void testKvMatcherGBKLikeFailure() throws Exception { AssertionError exc = assertionShouldFail( () -> assertThat( KV.of("key", ImmutableList.of(1, 2, 3)), SerializableMatchers.<String, Iterable<Integer>>kv( anything(), containsInAnyOrder(1, 2, 3, 4)))); assertThat(exc.getMessage(), Matchers.containsString("value did not match")); }
/** A {@link SerializableMatcher} with identical criteria to {@link Matchers#anything()}. */ public static SerializableMatcher<Object> anything() { return fromSupplier(Matchers::anything); }
@Test public void testContainsInAnyOrderSerializable() throws Exception { assertThat( ImmutableList.of(2, 1, 3), SerializableUtils.ensureSerializable(containsInAnyOrder(1, 2, 3))); }
/** * A {@link SerializableMatcher} that matches any {@link KV} with the specified value. * * <p>The value of type {@code V} will be serialized using the provided {@link Coder}. It is * explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <K, V> SerializableMatcher<KV<? extends K, ? extends V>> kvWithValue( Coder<V> coder, V value) { return new KvValueMatcher<>(equalTo(coder, value)); }
/** A {@link SerializableMatcher} with identical criteria to {@link Matchers#empty()}. */ public static <T> SerializableMatcher<Collection<? extends T>> empty() { return fromSupplier(Matchers::empty); }
@Test public void testContainsInAnyOrderNotSerializable() throws Exception { assertThat( ImmutableList.of(new NotSerializableClass()), SerializableUtils.ensureSerializable( containsInAnyOrder(new NotSerializableClassCoder(), new NotSerializableClass()))); }