Skip to content

Commit af83b6b

Browse files
committed
Merge pull request #993 from kcooney/AssumptionViolatedException-remove-unused-ctors
Remove unused constructors in the external AssumptionViolatedException.
2 parents c2f2a8c + d0b029f commit af83b6b

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

src/main/java/org/junit/Assume.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public static <T> void assumeThat(T actual, Matcher<T> matcher) {
101101
* If not, the test halts and is ignored.
102102
* Example:
103103
* <pre>:
104-
* assumeThat(1, is(1)); // passes
104+
* assumeThat("alwaysPasses", 1, is(1)); // passes
105105
* foo(); // will execute
106-
* assumeThat(0, is(1)); // assumption failure! test halts
106+
* assumeThat("alwaysFails", 0, is(1)); // assumption failure! test halts
107107
* int x = 1 / 0; // will never execute
108108
* </pre>
109109
*

src/main/java/org/junit/AssumptionViolatedException.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,33 @@
88
* fails should not generate a test case failure.
99
*
1010
* @see org.junit.Assume
11+
* @since 4.12
1112
*/
13+
@SuppressWarnings("deprecation")
1214
public class AssumptionViolatedException extends org.junit.internal.AssumptionViolatedException {
1315
private static final long serialVersionUID = 1L;
1416

15-
public AssumptionViolatedException(String assumption, boolean valueMatcher, Object value, Matcher<?> matcher) {
16-
super(assumption, valueMatcher, value, matcher);
17-
}
18-
1917
/**
20-
* An assumption exception with the given <i>value</i> (String or
21-
* Throwable) and an additional failing {@link Matcher}.
18+
* An assumption exception with the given <i>actual</i> value and a <i>matcher</i> describing
19+
* the expectation that failed.
2220
*/
23-
public AssumptionViolatedException(Object value, Matcher<?> matcher) {
24-
super(value, matcher);
21+
public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
22+
super(actual, matcher);
2523
}
2624

2725
/**
28-
* An assumption exception with the given <i>value</i> (String or
29-
* Throwable) and an additional failing {@link Matcher}.
26+
* An assumption exception with a message with the given <i>actual</i> value and a
27+
* <i>matcher</i> describing the expectation that failed.
3028
*/
31-
public AssumptionViolatedException(String assumption, Object value, Matcher<?> matcher) {
32-
super(assumption, value, matcher);
29+
public <T> AssumptionViolatedException(String message, T expected, Matcher<T> matcher) {
30+
super(message, expected, matcher);
3331
}
3432

3533
/**
3634
* An assumption exception with the given message only.
3735
*/
38-
public AssumptionViolatedException(String assumption) {
39-
super(assumption);
36+
public AssumptionViolatedException(String message) {
37+
super(message);
4038
}
4139

4240
/**

src/main/java/org/junit/internal/AssumptionViolatedException.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
* fails should not generate a test case failure.
1212
*
1313
* @see org.junit.Assume
14-
*
15-
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
1614
*/
17-
@Deprecated
1815
public class AssumptionViolatedException extends RuntimeException implements SelfDescribing {
1916
private static final long serialVersionUID = 2L;
2017

@@ -28,11 +25,15 @@ public class AssumptionViolatedException extends RuntimeException implements Sel
2825
private final Object fValue;
2926
private final Matcher<?> fMatcher;
3027

31-
public AssumptionViolatedException(String assumption, boolean valueMatcher, Object value, Matcher<?> matcher) {
28+
/**
29+
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
30+
*/
31+
@Deprecated
32+
public AssumptionViolatedException(String assumption, boolean hasValue, Object value, Matcher<?> matcher) {
3233
this.fAssumption = assumption;
3334
this.fValue = value;
3435
this.fMatcher = matcher;
35-
this.fValueMatcher = valueMatcher;
36+
this.fValueMatcher = hasValue;
3637

3738
if (value instanceof Throwable) {
3839
initCause((Throwable) value);
@@ -42,31 +43,44 @@ public AssumptionViolatedException(String assumption, boolean valueMatcher, Obje
4243
/**
4344
* An assumption exception with the given <i>value</i> (String or
4445
* Throwable) and an additional failing {@link Matcher}.
46+
*
47+
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
4548
*/
49+
@Deprecated
4650
public AssumptionViolatedException(Object value, Matcher<?> matcher) {
4751
this(null, true, value, matcher);
4852
}
4953

5054
/**
5155
* An assumption exception with the given <i>value</i> (String or
5256
* Throwable) and an additional failing {@link Matcher}.
57+
*
58+
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
5359
*/
60+
@Deprecated
5461
public AssumptionViolatedException(String assumption, Object value, Matcher<?> matcher) {
5562
this(assumption, true, value, matcher);
5663
}
5764

5865
/**
5966
* An assumption exception with the given message only.
67+
*
68+
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
6069
*/
70+
@Deprecated
6171
public AssumptionViolatedException(String assumption) {
6272
this(assumption, false, null, null);
6373
}
6474

6575
/**
6676
* An assumption exception with the given message and a cause.
77+
*
78+
* @deprecated Please use {@link org.junit.AssumptionViolatedException} instead.
6779
*/
80+
@Deprecated
6881
public AssumptionViolatedException(String assumption, Throwable e) {
69-
this(assumption, false, e, null);
82+
this(assumption, false, null, null);
83+
initCause(e);
7084
}
7185

7286
@Override
@@ -80,6 +94,7 @@ public void describeTo(Description description) {
8094
}
8195

8296
if (fValueMatcher) {
97+
// a value was passed in when this instance was constructed; print it
8398
if (fAssumption != null) {
8499
description.appendText(": ");
85100
}

src/test/java/org/junit/AssumptionViolatedExceptionTest.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import static org.hamcrest.CoreMatchers.containsString;
44
import static org.hamcrest.CoreMatchers.is;
55
import static org.hamcrest.CoreMatchers.notNullValue;
6+
import static org.hamcrest.CoreMatchers.nullValue;
67
import static org.junit.Assert.assertThat;
78
import static org.junit.Assume.assumeThat;
8-
99
import org.hamcrest.Matcher;
1010
import org.hamcrest.StringDescription;
1111
import org.junit.experimental.theories.DataPoint;
@@ -16,23 +16,23 @@
1616
@RunWith(Theories.class)
1717
public class AssumptionViolatedExceptionTest {
1818
@DataPoint
19-
public static Object TWO = 2;
19+
public static Integer TWO = 2;
2020

2121
@DataPoint
22-
public static Matcher<?> IS_THREE = is(3);
22+
public static Matcher<Integer> IS_THREE = is(3);
2323

2424
@DataPoint
25-
public static Matcher<?> NULL = null;
25+
public static Matcher<Integer> NULL = null;
2626

2727
@Theory
28-
public void toStringReportsMatcher(Object actual, Matcher<?> matcher) {
28+
public void toStringReportsMatcher(Integer actual, Matcher<Integer> matcher) {
2929
assumeThat(matcher, notNullValue());
3030
assertThat(new AssumptionViolatedException(actual, matcher).toString(),
3131
containsString(matcher.toString()));
3232
}
3333

3434
@Theory
35-
public void toStringReportsValue(Object actual, Matcher<?> matcher) {
35+
public void toStringReportsValue(Integer actual, Matcher<Integer> matcher) {
3636
assertThat(new AssumptionViolatedException(actual, matcher).toString(),
3737
containsString(String.valueOf(actual)));
3838
}
@@ -58,26 +58,32 @@ public void canInitCauseWithInstanceCreatedWithString() {
5858
}
5959

6060
@Test
61+
@SuppressWarnings("deprecation")
6162
public void canSetCauseWithInstanceCreatedWithObjectAndMatcher() {
6263
Throwable testObject = new Exception();
63-
AssumptionViolatedException e = new AssumptionViolatedException(testObject, containsString("test matcher"));
64+
org.junit.internal.AssumptionViolatedException e
65+
= new org.junit.internal.AssumptionViolatedException(
66+
testObject, containsString("test matcher"));
6467
assertThat(e.getCause(), is(testObject));
6568
}
6669

6770
@Test
71+
@SuppressWarnings("deprecation")
6872
public void canSetCauseWithInstanceCreatedWithAssumptionObjectAndMatcher() {
6973
Throwable testObject = new Exception();
70-
AssumptionViolatedException e = new AssumptionViolatedException(
71-
"sample assumption", testObject, containsString("test matcher"));
72-
74+
org.junit.internal.AssumptionViolatedException e
75+
= new org.junit.internal.AssumptionViolatedException(
76+
"sample assumption", testObject, containsString("test matcher"));
7377
assertThat(e.getCause(), is(testObject));
7478
}
7579

7680
@Test
81+
@SuppressWarnings("deprecation")
7782
public void canSetCauseWithInstanceCreatedWithMainConstructor() {
7883
Throwable testObject = new Exception();
79-
AssumptionViolatedException e = new AssumptionViolatedException(
80-
"sample assumption", false, testObject, containsString("test matcher"));
84+
org.junit.internal.AssumptionViolatedException e
85+
= new org.junit.internal.AssumptionViolatedException(
86+
"sample assumption", false, testObject, containsString("test matcher"));
8187
assertThat(e.getCause(), is(testObject));
8288
}
8389

0 commit comments

Comments
 (0)