/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and value of type {@code * T}, encoding followed by decoding yields an equal value of type {@code T}. */ public static <T> void coderDecodeEncodeEqualInContext( Coder<T> coder, Coder.Context context, T value) throws Exception { assertThat(decodeEncode(coder, context, value), equalTo(value)); }
/** * Verifies that for the given {@code Coder<Collection<T>>}, and value of type {@code * Collection<T>}, encoding followed by decoding yields an equal value of type {@code * Collection<T>}, in the given {@code Coder.Context}. */ @SuppressWarnings("unchecked") public static <T, CollectionT extends Collection<T>> void coderDecodeEncodeContentsEqualInContext( Coder<CollectionT> coder, Coder.Context context, CollectionT value) throws Exception { // Matchers.containsInAnyOrder() requires at least one element Collection<T> result = decodeEncode(coder, context, value); if (value.isEmpty()) { assertThat(result, emptyIterable()); } else { // This is the only Matchers.containInAnyOrder() overload that takes literal values assertThat(result, containsInAnyOrder((T[]) value.toArray())); } }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and value of type {@code * T}, the structural value is equal to the structural value yield by encoding and decoding the * original value, in any {@code Coder.Context}. */ public static <T> void structuralValueDecodeEncodeEqualInContext( Coder<T> coder, Coder.Context context, T value) throws Exception { assertEquals( coder.structuralValue(value), coder.structuralValue(decodeEncode(coder, context, value))); }
/** * Verifies that for the given {@code Coder<Iterable<T>>}, and value of type {@code Iterable<T>}, * encoding followed by decoding yields an equal value of type {@code Collection<T>}, in the given * {@code Coder.Context}. */ @SuppressWarnings("unchecked") public static <T, IterableT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext( Coder<IterableT> coder, Coder.Context context, IterableT value) throws Exception { Iterable<T> result = decodeEncode(coder, context, value); // Matchers.contains() requires at least one element if (Iterables.isEmpty(value)) { assertThat(result, emptyIterable()); } else { // This is the only Matchers.contains() overload that takes literal values assertThat(result, contains((T[]) Iterables.toArray(value, Object.class))); } }