Class SerializableMatcherDescription<T>

  • All Implemented Interfaces:
    java.io.Serializable, org.hamcrest.Matcher<T>, org.hamcrest.SelfDescribing

    class SerializableMatcherDescription<T>
    extends org.hamcrest.BaseMatcher<T>
    implements java.io.Serializable
    This class exists solely to provide a serializable description of a matcher to be serialized as a field in AssumptionViolatedException. Being a Throwable, it is required to be Serializable, but most implementations of Matcher are not. This class works around that limitation as AssumptionViolatedException only every uses the description of the Matcher, while still retaining backwards compatibility with classes compiled against its class signature before 4.14 and/or deserialization of previously serialized instances.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String matcherDescription  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T> org.hamcrest.Matcher<T> asSerializableMatcher​(org.hamcrest.Matcher<T> matcher)
      Factory method that checks to see if the matcher is already serializable.
      void describeTo​(org.hamcrest.Description description)  
      boolean matches​(java.lang.Object o)  
      • Methods inherited from class org.hamcrest.BaseMatcher

        _dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, isNotNull, toString
      • Methods inherited from class java.lang.Object

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

      • matcherDescription

        private final java.lang.String matcherDescription
    • Constructor Detail

      • SerializableMatcherDescription

        private SerializableMatcherDescription​(org.hamcrest.Matcher<T> matcher)
    • Method Detail

      • matches

        public boolean matches​(java.lang.Object o)
        Specified by:
        matches in interface org.hamcrest.Matcher<T>
      • describeTo

        public void describeTo​(org.hamcrest.Description description)
        Specified by:
        describeTo in interface org.hamcrest.SelfDescribing
      • asSerializableMatcher

        static <T> org.hamcrest.Matcher<T> asSerializableMatcher​(org.hamcrest.Matcher<T> matcher)
        Factory method that checks to see if the matcher is already serializable.
        Parameters:
        matcher - the matcher to make serializable
        Returns:
        The provided matcher if it is null or already serializable, the SerializableMatcherDescription representation of it if it is not.