Class SerializableMatcherDescription<T>

java.lang.Object
org.hamcrest.BaseMatcher<T>
org.junit.internal.SerializableMatcherDescription<T>
All Implemented Interfaces:
Serializable, org.hamcrest.Matcher<T>, org.hamcrest.SelfDescribing

class SerializableMatcherDescription<T> extends org.hamcrest.BaseMatcher<T> implements 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 final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    SerializableMatcherDescription(org.hamcrest.Matcher<T> matcher)
     
  • Method Summary

    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
     

    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 Details

    • matcherDescription

      private final String matcherDescription
  • Constructor Details

    • SerializableMatcherDescription

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

    • matches

      public boolean matches(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.