diff options
author | David Srbecky <dsrbecky@google.com> | 2021-02-24 18:57:51 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-24 18:57:51 +0000 |
commit | 91c5e5ff9d71ebc00818b310c09b175016c36dc2 (patch) | |
tree | 81124de095a6b4a53b223d0f70cadde9744ee44a /src/main/java/org/junit/internal/SerializableMatcherDescription.java | |
parent | 82af4b8b1d440f44b6ebac4db1fd61ae1d35a15e (diff) | |
parent | 23e304a839c5924c7ac7399076318adc511e9985 (diff) | |
download | junit-91c5e5ff9d71ebc00818b310c09b175016c36dc2.tar.gz |
Merge changes from topic "revert-1601635-AIQYZOHWTP" am: 565f36d281 am: 23e304a839
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1605377
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I443f57dd29ed2557b7733b1f3e51718d5d6a2af4
Diffstat (limited to 'src/main/java/org/junit/internal/SerializableMatcherDescription.java')
-rw-r--r-- | src/main/java/org/junit/internal/SerializableMatcherDescription.java | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/main/java/org/junit/internal/SerializableMatcherDescription.java b/src/main/java/org/junit/internal/SerializableMatcherDescription.java deleted file mode 100644 index e036557..0000000 --- a/src/main/java/org/junit/internal/SerializableMatcherDescription.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.junit.internal; - -import java.io.Serializable; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; - -/** - * This class exists solely to provide a serializable description of a matcher to be serialized as a field in - * {@link AssumptionViolatedException}. Being a {@link Throwable}, it is required to be {@link Serializable}, but most - * implementations of {@link Matcher} are not. This class works around that limitation as - * {@link AssumptionViolatedException} only every uses the description of the {@link Matcher}, while still retaining - * backwards compatibility with classes compiled against its class signature before 4.14 and/or deserialization of - * previously serialized instances. - */ -class SerializableMatcherDescription<T> extends BaseMatcher<T> implements Serializable { - - private final String matcherDescription; - - private SerializableMatcherDescription(Matcher<T> matcher) { - matcherDescription = StringDescription.asString(matcher); - } - - public boolean matches(Object o) { - throw new UnsupportedOperationException("This Matcher implementation only captures the description"); - } - - public void describeTo(Description description) { - description.appendText(matcherDescription); - } - - /** - * Factory method that checks to see if the matcher is already serializable. - * @param matcher the matcher to make serializable - * @return The provided matcher if it is null or already serializable, - * the SerializableMatcherDescription representation of it if it is not. - */ - static <T> Matcher<T> asSerializableMatcher(Matcher<T> matcher) { - if (matcher == null || matcher instanceof Serializable) { - return matcher; - } else { - return new SerializableMatcherDescription<T>(matcher); - } - } -} |