From d0b029f644e2f3217962f0de0cd4ffdfa641bd96 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Wed, 10 Sep 2014 09:48:47 -0700 Subject: [PATCH] Remove unused constructors in external AssumptionViolatedException. --- src/main/java/org/junit/Assume.java | 4 +-- .../junit/AssumptionViolatedException.java | 26 ++++++++-------- .../internal/AssumptionViolatedException.java | 27 +++++++++++++---- .../AssumptionViolatedExceptionTest.java | 30 +++++++++++-------- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/junit/Assume.java b/src/main/java/org/junit/Assume.java index 4bfb3e717b39..b7687f7c1ffa 100644 --- a/src/main/java/org/junit/Assume.java +++ b/src/main/java/org/junit/Assume.java @@ -101,9 +101,9 @@ public static void assumeThat(T actual, Matcher matcher) { * If not, the test halts and is ignored. * Example: *
:
-     *   assumeThat(1, is(1)); // passes
+     *   assumeThat("alwaysPasses", 1, is(1)); // passes
      *   foo(); // will execute
-     *   assumeThat(0, is(1)); // assumption failure! test halts
+     *   assumeThat("alwaysFails", 0, is(1)); // assumption failure! test halts
      *   int x = 1 / 0; // will never execute
      * 
* diff --git a/src/main/java/org/junit/AssumptionViolatedException.java b/src/main/java/org/junit/AssumptionViolatedException.java index fc4e91e21b3a..e48ddf000a78 100644 --- a/src/main/java/org/junit/AssumptionViolatedException.java +++ b/src/main/java/org/junit/AssumptionViolatedException.java @@ -8,35 +8,33 @@ * fails should not generate a test case failure. * * @see org.junit.Assume + * @since 4.12 */ +@SuppressWarnings("deprecation") public class AssumptionViolatedException extends org.junit.internal.AssumptionViolatedException { private static final long serialVersionUID = 1L; - public AssumptionViolatedException(String assumption, boolean valueMatcher, Object value, Matcher matcher) { - super(assumption, valueMatcher, value, matcher); - } - /** - * An assumption exception with the given value (String or - * Throwable) and an additional failing {@link Matcher}. + * An assumption exception with the given actual value and a matcher describing + * the expectation that failed. */ - public AssumptionViolatedException(Object value, Matcher matcher) { - super(value, matcher); + public AssumptionViolatedException(T actual, Matcher matcher) { + super(actual, matcher); } /** - * An assumption exception with the given value (String or - * Throwable) and an additional failing {@link Matcher}. + * An assumption exception with a message with the given actual value and a + * matcher describing the expectation that failed. */ - public AssumptionViolatedException(String assumption, Object value, Matcher matcher) { - super(assumption, value, matcher); + public AssumptionViolatedException(String message, T expected, Matcher matcher) { + super(message, expected, matcher); } /** * An assumption exception with the given message only. */ - public AssumptionViolatedException(String assumption) { - super(assumption); + public AssumptionViolatedException(String message) { + super(message); } /** diff --git a/src/main/java/org/junit/internal/AssumptionViolatedException.java b/src/main/java/org/junit/internal/AssumptionViolatedException.java index 7e8d9a7b0489..880d73f9af60 100644 --- a/src/main/java/org/junit/internal/AssumptionViolatedException.java +++ b/src/main/java/org/junit/internal/AssumptionViolatedException.java @@ -11,10 +11,7 @@ * fails should not generate a test case failure. * * @see org.junit.Assume - * - * @deprecated Please use {@link org.junit.AssumptionViolatedException} instead. */ -@Deprecated public class AssumptionViolatedException extends RuntimeException implements SelfDescribing { private static final long serialVersionUID = 2L; @@ -28,11 +25,15 @@ public class AssumptionViolatedException extends RuntimeException implements Sel private final Object fValue; private final Matcher fMatcher; - public AssumptionViolatedException(String assumption, boolean valueMatcher, Object value, Matcher matcher) { + /** + * @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 = valueMatcher; + this.fValueMatcher = hasValue; if (value instanceof Throwable) { initCause((Throwable) value); @@ -42,7 +43,10 @@ public AssumptionViolatedException(String assumption, boolean valueMatcher, Obje /** * An assumption exception with the given value (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); } @@ -50,23 +54,33 @@ public AssumptionViolatedException(Object value, Matcher matcher) { /** * An assumption exception with the given value (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, e, null); + this(assumption, false, null, null); + initCause(e); } @Override @@ -80,6 +94,7 @@ public void describeTo(Description description) { } if (fValueMatcher) { + // a value was passed in when this instance was constructed; print it if (fAssumption != null) { description.appendText(": "); } diff --git a/src/test/java/org/junit/AssumptionViolatedExceptionTest.java b/src/test/java/org/junit/AssumptionViolatedExceptionTest.java index a1ce2fb2870b..18deb9e18367 100644 --- a/src/test/java/org/junit/AssumptionViolatedExceptionTest.java +++ b/src/test/java/org/junit/AssumptionViolatedExceptionTest.java @@ -3,9 +3,9 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import static org.junit.Assume.assumeThat; - import org.hamcrest.Matcher; import org.hamcrest.StringDescription; import org.junit.experimental.theories.DataPoint; @@ -16,23 +16,23 @@ @RunWith(Theories.class) public class AssumptionViolatedExceptionTest { @DataPoint - public static Object TWO = 2; + public static Integer TWO = 2; @DataPoint - public static Matcher IS_THREE = is(3); + public static Matcher IS_THREE = is(3); @DataPoint - public static Matcher NULL = null; + public static Matcher NULL = null; @Theory - public void toStringReportsMatcher(Object actual, Matcher matcher) { + public void toStringReportsMatcher(Integer actual, Matcher matcher) { assumeThat(matcher, notNullValue()); assertThat(new AssumptionViolatedException(actual, matcher).toString(), containsString(matcher.toString())); } @Theory - public void toStringReportsValue(Object actual, Matcher matcher) { + public void toStringReportsValue(Integer actual, Matcher matcher) { assertThat(new AssumptionViolatedException(actual, matcher).toString(), containsString(String.valueOf(actual))); } @@ -58,26 +58,32 @@ public void canInitCauseWithInstanceCreatedWithString() { } @Test + @SuppressWarnings("deprecation") public void canSetCauseWithInstanceCreatedWithObjectAndMatcher() { Throwable testObject = new Exception(); - AssumptionViolatedException e = new AssumptionViolatedException(testObject, containsString("test matcher")); + org.junit.internal.AssumptionViolatedException e + = new org.junit.internal.AssumptionViolatedException( + testObject, containsString("test matcher")); assertThat(e.getCause(), is(testObject)); } @Test + @SuppressWarnings("deprecation") public void canSetCauseWithInstanceCreatedWithAssumptionObjectAndMatcher() { Throwable testObject = new Exception(); - AssumptionViolatedException e = new AssumptionViolatedException( - "sample assumption", testObject, containsString("test matcher")); - + org.junit.internal.AssumptionViolatedException e + = new org.junit.internal.AssumptionViolatedException( + "sample assumption", testObject, containsString("test matcher")); assertThat(e.getCause(), is(testObject)); } @Test + @SuppressWarnings("deprecation") public void canSetCauseWithInstanceCreatedWithMainConstructor() { Throwable testObject = new Exception(); - AssumptionViolatedException e = new AssumptionViolatedException( - "sample assumption", false, testObject, containsString("test matcher")); + org.junit.internal.AssumptionViolatedException e + = new org.junit.internal.AssumptionViolatedException( + "sample assumption", false, testObject, containsString("test matcher")); assertThat(e.getCause(), is(testObject)); }