Skip to content

Commit

Permalink
Remove unused constructors in external AssumptionViolatedException.
Browse files Browse the repository at this point in the history
  • Loading branch information
kcooney committed Sep 24, 2014
1 parent c2f2a8c commit d0b029f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/junit/Assume.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public static <T> void assumeThat(T actual, Matcher<T> matcher) {
* If not, the test halts and is ignored.
* Example:
* <pre>:
* 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
* </pre>
*
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/org/junit/AssumptionViolatedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>value</i> (String or
* Throwable) and an additional failing {@link Matcher}.
* An assumption exception with the given <i>actual</i> value and a <i>matcher</i> describing
* the expectation that failed.
*/
public AssumptionViolatedException(Object value, Matcher<?> matcher) {
super(value, matcher);
public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
super(actual, matcher);
}

/**
* An assumption exception with the given <i>value</i> (String or
* Throwable) and an additional failing {@link Matcher}.
* An assumption exception with a message with the given <i>actual</i> value and a
* <i>matcher</i> describing the expectation that failed.
*/
public AssumptionViolatedException(String assumption, Object value, Matcher<?> matcher) {
super(assumption, value, matcher);
public <T> AssumptionViolatedException(String message, T expected, Matcher<T> 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);
}

/**
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/org/junit/internal/AssumptionViolatedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -42,31 +43,44 @@ public AssumptionViolatedException(String assumption, boolean valueMatcher, Obje
/**
* 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, e, null);
this(assumption, false, null, null);
initCause(e);
}

@Override
Expand All @@ -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(": ");
}
Expand Down
30 changes: 18 additions & 12 deletions src/test/java/org/junit/AssumptionViolatedExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Integer> IS_THREE = is(3);

@DataPoint
public static Matcher<?> NULL = null;
public static Matcher<Integer> NULL = null;

@Theory
public void toStringReportsMatcher(Object actual, Matcher<?> matcher) {
public void toStringReportsMatcher(Integer actual, Matcher<Integer> 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<Integer> matcher) {
assertThat(new AssumptionViolatedException(actual, matcher).toString(),
containsString(String.valueOf(actual)));
}
Expand All @@ -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));
}

Expand Down

0 comments on commit d0b029f

Please sign in to comment.