Class CoderProperties


  • public class CoderProperties
    extends java.lang.Object
    Properties for use in Coder tests. These are implemented with junit assertions rather than as predicates for the sake of error messages.

    We serialize and deserialize the coder to make sure that any state information required by the coder is preserved. This causes tests written such that coders that lose information during serialization or change state during encoding/decoding will fail.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.List<Coder.Context> ALL_CONTEXTS
      All the contexts, for use in test cases.
    • Constructor Summary

      Constructors 
      Constructor Description
      CoderProperties()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void coderConsistentWithEquals​(Coder<T> coder, T value1, T value2)
      Verifies that for the given Coder<T> and values of type T, the values are equal if and only if the encoded bytes are equal.
      static <T> void coderConsistentWithEqualsInContext​(Coder<T> coder, Coder.Context context, T value1, T value2)
      Verifies that for the given Coder<T>, Coder.Context, and values of type T, the values are equal if and only if the encoded bytes are equal, in any Coder.Context.
      static <T,​CollectionT extends java.util.Collection<T>>
      void
      coderDecodeEncodeContentsEqual​(Coder<CollectionT> coder, CollectionT value)
      Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in any Coder.Context.
      static <T,​CollectionT extends java.util.Collection<T>>
      void
      coderDecodeEncodeContentsEqualInContext​(Coder<CollectionT> coder, Coder.Context context, CollectionT value)
      Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in the given Coder.Context.
      static <T,​IterableT extends java.lang.Iterable<T>>
      void
      coderDecodeEncodeContentsInSameOrder​(Coder<IterableT> coder, IterableT value)
      Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in any Coder.Context.
      static <T,​IterableT extends java.lang.Iterable<T>>
      void
      coderDecodeEncodeContentsInSameOrderInContext​(Coder<IterableT> coder, Coder.Context context, IterableT value)
      Verifies that for the given Coder<Iterable<T>>, and value of type Iterable<T>, encoding followed by decoding yields an equal value of type Collection<T>, in the given Coder.Context.
      static <T> void coderDecodeEncodeEqual​(Coder<T> coder, T value)
      Verifies that for the given Coder<T>, and value of type T, encoding followed by decoding yields an equal value of type T, in any Coder.Context.
      static <T> void coderDecodeEncodeEqualInContext​(Coder<T> coder, Coder.Context context, T value)
      Verifies that for the given Coder<T>, Coder.Context, and value of type T, encoding followed by decoding yields an equal value of type T.
      static <T> void coderDecodeEncodeInContext​(Coder<T> coder, Coder.Context context, T value, org.hamcrest.Matcher<T> matcher)
      Verifies that for the given Coder<T>, Coder.Context, and value of type T, encoding followed by decoding yields a value of type T and tests that the matcher succeeds on the values.
      static <T> void coderDecodesBase64​(Coder<T> coder, java.lang.String base64Encoding, T value)  
      static <T> void coderDecodesBase64​(Coder<T> coder, java.util.List<java.lang.String> base64Encodings, java.util.List<T> values)  
      static <T,​IterableT extends java.lang.Iterable<T>>
      void
      coderDecodesBase64ContentsEqual​(Coder<IterableT> coder, java.lang.String base64Encoding, IterableT expected)  
      static <T,​IterableT extends java.lang.Iterable<T>>
      void
      coderDecodesBase64ContentsEqual​(Coder<IterableT> coder, java.util.List<java.lang.String> base64Encodings, java.util.List<IterableT> expected)  
      static <T> void coderDeterministic​(Coder<T> coder, T value1, T value2)
      Verifies that for the given Coder<T>, and values of type T, if the values are equal then the encoded bytes are equal, in any Coder.Context.
      static <T> void coderDeterministicInContext​(Coder<T> coder, Coder.Context context, T value1, T value2)
      Verifies that for the given Coder<T>, Coder.Context, and values of type T, if the values are equal then the encoded bytes are equal.
      static <T> void coderEncodesBase64​(Coder<T> coder, java.util.List<T> values, java.util.List<java.lang.String> base64Encodings)  
      static <T> void coderEncodesBase64​(Coder<T> coder, T value, java.lang.String base64Encoding)  
      static <T> void coderSerializable​(Coder<T> coder)
      Verifies that the given Coder<T> can be correctly serialized and deserialized.
      static <T> void structuralValueConsistentWithEquals​(Coder<T> coder, T value1, T value2)
      Verifies that for the given Coder<T> and values of type T, the structural values are equal if and only if the encoded bytes are equal.
      static <T> void structuralValueConsistentWithEqualsInContext​(Coder<T> coder, Coder.Context context, T value1, T value2)
      Verifies that for the given Coder<T>, Coder.Context, and values of type T, the structural values are equal if and only if the encoded bytes are equal, in any Coder.Context.
      static <T> void structuralValueDecodeEncodeEqual​(Coder<T> coder, T value)
      Verifies that for the given Coder<T> and value of type T, the structural value is equal to the structural value yield by encoding and decoding the original value.
      static <T> void structuralValueDecodeEncodeEqualInContext​(Coder<T> coder, Coder.Context context, T value)
      Verifies that for the given Coder<T>, Coder.Context, and value of type T, the structural value is equal to the structural value yield by encoding and decoding the original value, in any Coder.Context.
      static <T extends java.lang.Iterable<?>>
      void
      structuralValueDecodeEncodeEqualIterable​(Coder<T> coder, T value)
      Verifies that for the given Coder<T> and value of type T, the structural value of the content of the Iterable is equal to the structural value yield by encoding and decoding the original value.
      static <T extends java.lang.Iterable<?>>
      void
      structuralValueDecodeEncodeEqualIterableInContext​(Coder<T> coder, Coder.Context context, T value)
      Verifies that for the given Coder<T>, Coder.Context, and value of type T, the structural content of the Iterable of the value is equal to the structural value yield by encoding and decoding the original value, in any Coder.Context.
      static <T> void testByteCount​(Coder<T> coder, Coder.Context context, T[] elements)
      A utility method that passes the given (unencoded) elements through coder's registerByteSizeObserver() and encode() methods, and confirms they are mutually consistent.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ALL_CONTEXTS

        public static final java.util.List<Coder.Context> ALL_CONTEXTS
        All the contexts, for use in test cases.
    • Constructor Detail

      • CoderProperties

        public CoderProperties()
    • Method Detail

      • coderDeterministic

        public static <T> void coderDeterministic​(Coder<T> coder,
                                                  T value1,
                                                  T value2)
                                           throws java.lang.Exception
        Verifies that for the given Coder<T>, and values of type T, if the values are equal then the encoded bytes are equal, in any Coder.Context.
        Throws:
        java.lang.Exception
      • coderDeterministicInContext

        public static <T> void coderDeterministicInContext​(Coder<T> coder,
                                                           Coder.Context context,
                                                           T value1,
                                                           T value2)
                                                    throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and values of type T, if the values are equal then the encoded bytes are equal.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeEqual

        public static <T> void coderDecodeEncodeEqual​(Coder<T> coder,
                                                      T value)
                                               throws java.lang.Exception
        Verifies that for the given Coder<T>, and value of type T, encoding followed by decoding yields an equal value of type T, in any Coder.Context.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeEqualInContext

        public static <T> void coderDecodeEncodeEqualInContext​(Coder<T> coder,
                                                               Coder.Context context,
                                                               T value)
                                                        throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and value of type T, encoding followed by decoding yields an equal value of type T.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeInContext

        public static <T> void coderDecodeEncodeInContext​(Coder<T> coder,
                                                          Coder.Context context,
                                                          T value,
                                                          org.hamcrest.Matcher<T> matcher)
                                                   throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and value of type T, encoding followed by decoding yields a value of type T and tests that the matcher succeeds on the values.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeContentsEqual

        public static <T,​CollectionT extends java.util.Collection<T>> void coderDecodeEncodeContentsEqual​(Coder<CollectionT> coder,
                                                                                                                CollectionT value)
                                                                                                         throws java.lang.Exception
        Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in any Coder.Context.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeContentsEqualInContext

        public static <T,​CollectionT extends java.util.Collection<T>> void coderDecodeEncodeContentsEqualInContext​(Coder<CollectionT> coder,
                                                                                                                         Coder.Context context,
                                                                                                                         CollectionT value)
                                                                                                                  throws java.lang.Exception
        Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in the given Coder.Context.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeContentsInSameOrder

        public static <T,​IterableT extends java.lang.Iterable<T>> void coderDecodeEncodeContentsInSameOrder​(Coder<IterableT> coder,
                                                                                                                  IterableT value)
                                                                                                           throws java.lang.Exception
        Verifies that for the given Coder<Collection<T>>, and value of type Collection<T>, encoding followed by decoding yields an equal value of type Collection<T>, in any Coder.Context.
        Throws:
        java.lang.Exception
      • coderDecodeEncodeContentsInSameOrderInContext

        public static <T,​IterableT extends java.lang.Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext​(Coder<IterableT> coder,
                                                                                                                           Coder.Context context,
                                                                                                                           IterableT value)
                                                                                                                    throws java.lang.Exception
        Verifies that for the given Coder<Iterable<T>>, and value of type Iterable<T>, encoding followed by decoding yields an equal value of type Collection<T>, in the given Coder.Context.
        Throws:
        java.lang.Exception
      • coderSerializable

        public static <T> void coderSerializable​(Coder<T> coder)
        Verifies that the given Coder<T> can be correctly serialized and deserialized.
      • coderConsistentWithEquals

        public static <T> void coderConsistentWithEquals​(Coder<T> coder,
                                                         T value1,
                                                         T value2)
                                                  throws java.lang.Exception
        Verifies that for the given Coder<T> and values of type T, the values are equal if and only if the encoded bytes are equal.
        Throws:
        java.lang.Exception
      • coderConsistentWithEqualsInContext

        public static <T> void coderConsistentWithEqualsInContext​(Coder<T> coder,
                                                                  Coder.Context context,
                                                                  T value1,
                                                                  T value2)
                                                           throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and values of type T, the values are equal if and only if the encoded bytes are equal, in any Coder.Context.
        Throws:
        java.lang.Exception
      • structuralValueConsistentWithEquals

        public static <T> void structuralValueConsistentWithEquals​(Coder<T> coder,
                                                                   T value1,
                                                                   T value2)
                                                            throws java.lang.Exception
        Verifies that for the given Coder<T> and values of type T, the structural values are equal if and only if the encoded bytes are equal.
        Throws:
        java.lang.Exception
      • structuralValueConsistentWithEqualsInContext

        public static <T> void structuralValueConsistentWithEqualsInContext​(Coder<T> coder,
                                                                            Coder.Context context,
                                                                            T value1,
                                                                            T value2)
                                                                     throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and values of type T, the structural values are equal if and only if the encoded bytes are equal, in any Coder.Context.
        Throws:
        java.lang.Exception
      • structuralValueDecodeEncodeEqual

        public static <T> void structuralValueDecodeEncodeEqual​(Coder<T> coder,
                                                                T value)
                                                         throws java.lang.Exception
        Verifies that for the given Coder<T> and value of type T, the structural value is equal to the structural value yield by encoding and decoding the original value.

        This is useful to test the correct implementation of a Coder structural equality with values that don't implement the equals contract.

        Throws:
        java.lang.Exception
      • structuralValueDecodeEncodeEqualIterable

        public static <T extends java.lang.Iterable<?>> void structuralValueDecodeEncodeEqualIterable​(Coder<T> coder,
                                                                                                      T value)
                                                                                               throws java.lang.Exception
        Verifies that for the given Coder<T> and value of type T, the structural value of the content of the Iterable is equal to the structural value yield by encoding and decoding the original value.

        This is useful to test the correct implementation of a Coder structural equality with values that don't implement the equals contract.

        Throws:
        java.lang.Exception
      • structuralValueDecodeEncodeEqualInContext

        public static <T> void structuralValueDecodeEncodeEqualInContext​(Coder<T> coder,
                                                                         Coder.Context context,
                                                                         T value)
                                                                  throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and value of type T, the structural value is equal to the structural value yield by encoding and decoding the original value, in any Coder.Context.
        Throws:
        java.lang.Exception
      • structuralValueDecodeEncodeEqualIterableInContext

        public static <T extends java.lang.Iterable<?>> void structuralValueDecodeEncodeEqualIterableInContext​(Coder<T> coder,
                                                                                                               Coder.Context context,
                                                                                                               T value)
                                                                                                        throws java.lang.Exception
        Verifies that for the given Coder<T>, Coder.Context, and value of type T, the structural content of the Iterable of the value is equal to the structural value yield by encoding and decoding the original value, in any Coder.Context.
        Throws:
        java.lang.Exception
      • coderDecodesBase64

        public static <T> void coderDecodesBase64​(Coder<T> coder,
                                                  java.lang.String base64Encoding,
                                                  T value)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • coderDecodesBase64

        public static <T> void coderDecodesBase64​(Coder<T> coder,
                                                  java.util.List<java.lang.String> base64Encodings,
                                                  java.util.List<T> values)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • coderEncodesBase64

        public static <T> void coderEncodesBase64​(Coder<T> coder,
                                                  T value,
                                                  java.lang.String base64Encoding)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • coderEncodesBase64

        public static <T> void coderEncodesBase64​(Coder<T> coder,
                                                  java.util.List<T> values,
                                                  java.util.List<java.lang.String> base64Encodings)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • coderDecodesBase64ContentsEqual

        public static <T,​IterableT extends java.lang.Iterable<T>> void coderDecodesBase64ContentsEqual​(Coder<IterableT> coder,
                                                                                                             java.lang.String base64Encoding,
                                                                                                             IterableT expected)
                                                                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • coderDecodesBase64ContentsEqual

        public static <T,​IterableT extends java.lang.Iterable<T>> void coderDecodesBase64ContentsEqual​(Coder<IterableT> coder,
                                                                                                             java.util.List<java.lang.String> base64Encodings,
                                                                                                             java.util.List<IterableT> expected)
                                                                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testByteCount

        public static <T> void testByteCount​(Coder<T> coder,
                                             Coder.Context context,
                                             T[] elements)
                                      throws java.lang.Exception
        A utility method that passes the given (unencoded) elements through coder's registerByteSizeObserver() and encode() methods, and confirms they are mutually consistent. This is useful for testing coder implementations.
        Throws:
        java.lang.Exception