aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/internal/AssumptionViolatedException.java
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2016-12-14 11:49:43 +0000
committerPaul Duffin <paulduffin@google.com>2016-12-20 15:52:52 +0000
commitaeb93fc33cae3aadbb9b46083350ad2dc9aea645 (patch)
treeb316db7dee11d1aeee3510562e036fd41705b8b5 /src/main/java/org/junit/internal/AssumptionViolatedException.java
parent26401927b83770db45f00706ccc589955644c6c2 (diff)
downloadjunit-aeb93fc33cae3aadbb9b46083350ad2dc9aea645.tar.gz
Upgrade to JUnit 4.12
The license has changed from Common Public License v1.0 to Eclipse Public License v1.0. This will not compile as it is because it is intended to be built against Hamcrest 1.3 or later but it is being built against Hamcrest 1.1. A follow on patch will fix the compilation errors so that it builds against Hamcrest 1.1. That allows Hamcrest to be upgraded separately. The patch can be reverted once Hamcrest has been upgraded. There are also some Android specific issues that will also be fixed in follow on patches. Bug: 33613916 Test: make checkbuild Change-Id: Ic2c983a030399e3ace1a14927cb143fbd8307b4f
Diffstat (limited to 'src/main/java/org/junit/internal/AssumptionViolatedException.java')
-rw-r--r--src/main/java/org/junit/internal/AssumptionViolatedException.java135
1 files changed, 103 insertions, 32 deletions
diff --git a/src/main/java/org/junit/internal/AssumptionViolatedException.java b/src/main/java/org/junit/internal/AssumptionViolatedException.java
index 8e11268..880d73f 100644
--- a/src/main/java/org/junit/internal/AssumptionViolatedException.java
+++ b/src/main/java/org/junit/internal/AssumptionViolatedException.java
@@ -5,36 +5,107 @@ import org.hamcrest.Matcher;
import org.hamcrest.SelfDescribing;
import org.hamcrest.StringDescription;
+/**
+ * An exception class used to implement <i>assumptions</i> (state in which a given test
+ * is meaningful and should or should not be executed). A test for which an assumption
+ * fails should not generate a test case failure.
+ *
+ * @see org.junit.Assume
+ */
public class AssumptionViolatedException extends RuntimeException implements SelfDescribing {
- private static final long serialVersionUID= 1L;
-
- private final Object fValue;
-
- private final Matcher<?> fMatcher;
-
- public AssumptionViolatedException(Object value, Matcher<?> matcher) {
- super(value instanceof Throwable ? (Throwable) value : null);
- fValue= value;
- fMatcher= matcher;
- }
-
- public AssumptionViolatedException(String assumption) {
- this(assumption, null);
- }
-
- @Override
- public String getMessage() {
- return StringDescription.asString(this);
- }
-
- public void describeTo(Description description) {
- if (fMatcher != null) {
- description.appendText("got: ");
- description.appendValue(fValue);
- description.appendText(", expected: ");
- description.appendDescriptionOf(fMatcher);
- } else {
- description.appendText("failed assumption: " + fValue);
- }
- }
-} \ No newline at end of file
+ private static final long serialVersionUID = 2L;
+
+ /*
+ * We have to use the f prefix until the next major release to ensure
+ * serialization compatibility.
+ * See https://github.com/junit-team/junit/issues/976
+ */
+ private final String fAssumption;
+ private final boolean fValueMatcher;
+ private final Object fValue;
+ private final Matcher<?> fMatcher;
+
+ /**
+ * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
+ */
+ @Deprecated
+ public AssumptionViolatedException(String assumption, boolean hasValue, Object value, Matcher<?> matcher) {
+ this.fAssumption = assumption;
+ this.fValue = value;
+ this.fMatcher = matcher;
+ this.fValueMatcher = hasValue;
+
+ if (value instanceof Throwable) {
+ initCause((Throwable) value);
+ }
+ }
+
+ /**
+ * An assumption exception with the given <i>value</i> (String or
+ * Throwable) and an additional failing {@link Matcher}.
+ *
+ * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
+ */
+ @Deprecated
+ public AssumptionViolatedException(Object value, Matcher<?> matcher) {
+ this(null, true, value, matcher);
+ }
+
+ /**
+ * An assumption exception with the given <i>value</i> (String or
+ * Throwable) and an additional failing {@link Matcher}.
+ *
+ * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
+ */
+ @Deprecated
+ public AssumptionViolatedException(String assumption, Object value, Matcher<?> matcher) {
+ this(assumption, true, value, matcher);
+ }
+
+ /**
+ * An assumption exception with the given message only.
+ *
+ * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
+ */
+ @Deprecated
+ public AssumptionViolatedException(String assumption) {
+ this(assumption, false, null, null);
+ }
+
+ /**
+ * An assumption exception with the given message and a cause.
+ *
+ * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
+ */
+ @Deprecated
+ public AssumptionViolatedException(String assumption, Throwable e) {
+ this(assumption, false, null, null);
+ initCause(e);
+ }
+
+ @Override
+ public String getMessage() {
+ return StringDescription.asString(this);
+ }
+
+ public void describeTo(Description description) {
+ if (fAssumption != null) {
+ description.appendText(fAssumption);
+ }
+
+ if (fValueMatcher) {
+ // a value was passed in when this instance was constructed; print it
+ if (fAssumption != null) {
+ description.appendText(": ");
+ }
+
+ description.appendText("got: ");
+ description.appendValue(fValue);
+
+ if (fMatcher != null) {
+ description.appendText(", expected: ");
+ description.appendDescriptionOf(fMatcher);
+ }
+ }
+ }
+}