Skip to content

Commit e5c3363

Browse files
committed
Deprecate APIs that use Hamcrest classes. Users should use the java-hamcrest library instead.
1 parent 4bef795 commit e5c3363

8 files changed

+31
-1
lines changed

Diff for: src/main/java/org/junit/Assert.java

+4
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,9 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
918918
* values
919919
* @see org.hamcrest.CoreMatchers
920920
* @see org.hamcrest.MatcherAssert
921+
* @deprecated use {@code org.hamcrest.junit.MatcherAssert.assertThat()}
921922
*/
923+
@Deprecated
922924
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
923925
assertThat("", actual, matcher);
924926
}
@@ -950,7 +952,9 @@ public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
950952
* values
951953
* @see org.hamcrest.CoreMatchers
952954
* @see org.hamcrest.MatcherAssert
955+
* @deprecated use {@code org.hamcrest.junit.MatcherAssert.assertThat()}
953956
*/
957+
@Deprecated
954958
public static <T> void assertThat(String reason, T actual,
955959
Matcher<? super T> matcher) {
956960
MatcherAssert.assertThat(reason, actual, matcher);

Diff for: src/main/java/org/junit/Assume.java

+2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public static void assumeNotNull(Object... objects) {
8989
* @param matcher an expression, built of {@link Matcher}s, specifying allowed values
9090
* @see org.hamcrest.CoreMatchers
9191
* @see org.junit.matchers.JUnitMatchers
92+
* @deprecated use {@code org.hamcrest.junit.MatcherAssume.assumeThat()}
9293
*/
94+
@Deprecated
9395
public static <T> void assumeThat(T actual, Matcher<T> matcher) {
9496
if (!matcher.matches(actual)) {
9597
throw new AssumptionViolatedException(actual, matcher);

Diff for: src/main/java/org/junit/AssumptionViolatedException.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class AssumptionViolatedException extends org.junit.internal.AssumptionVi
1818
* An assumption exception with the given <i>actual</i> value and a <i>matcher</i> describing
1919
* the expectation that failed.
2020
*/
21+
@Deprecated
2122
public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
2223
super(actual, matcher);
2324
}
@@ -26,6 +27,7 @@ public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
2627
* An assumption exception with a message with the given <i>actual</i> value and a
2728
* <i>matcher</i> describing the expectation that failed.
2829
*/
30+
@Deprecated
2931
public <T> AssumptionViolatedException(String message, T expected, Matcher<T> matcher) {
3032
super(message, expected, matcher);
3133
}

Diff for: src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
/**
1111
* A matcher that delegates to throwableMatcher and in addition appends the
1212
* stacktrace of the actual Throwable in case of a mismatch.
13+
*
14+
* @deprecated use {@code org.hamcrest.junit.JunitMatchers.isThrowable()}
15+
* or {@code org.hamcrest.junit.JunitMatchers.isException()}
1316
*/
17+
@Deprecated
1418
public class StacktracePrintingMatcher<T extends Throwable> extends
1519
org.hamcrest.TypeSafeMatcher<T> {
1620

Diff for: src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* match.
1111
*
1212
* @param <T> the type of the throwable being matched
13+
* @deprecated use {@code org.hamcrest.junit.ExpectedException}
1314
*/
15+
@Deprecated
1416
public class ThrowableCauseMatcher<T extends Throwable> extends
1517
TypeSafeMatcher<T> {
1618

Diff for: src/main/java/org/junit/matchers/JUnitMatchers.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
* not currently included in the basic CoreMatchers class from hamcrest.
1212
*
1313
* @since 4.4
14+
* @deprecated use {@code org.hamcrest.junit.JUnitMatchers}
1415
*/
16+
@Deprecated
1517
public class JUnitMatchers {
1618
/**
1719
* @return A matcher matching any collection containing element

Diff for: src/main/java/org/junit/rules/ErrorCollector.java

+6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public void addError(Throwable error) {
4949
/**
5050
* Adds a failure to the table if {@code matcher} does not match {@code value}.
5151
* Execution continues, but the test will fail at the end if the match fails.
52+
*
53+
* @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()}
5254
*/
55+
@Deprecated
5356
public <T> void checkThat(final T value, final Matcher<T> matcher) {
5457
checkThat("", value, matcher);
5558
}
@@ -58,7 +61,10 @@ public <T> void checkThat(final T value, final Matcher<T> matcher) {
5861
* Adds a failure with the given {@code reason}
5962
* to the table if {@code matcher} does not match {@code value}.
6063
* Execution continues, but the test will fail at the end if the match fails.
64+
*
65+
* @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()}
6166
*/
67+
@Deprecated
6268
public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) {
6369
checkSucceeds(new Callable<Object>() {
6470
public Object call() throws Exception {

Diff for: src/main/java/org/junit/rules/ExpectedException.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import static org.junit.Assert.fail;
88
import static org.junit.internal.matchers.ThrowableCauseMatcher.hasCause;
99
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
10-
1110
import org.hamcrest.Matcher;
1211
import org.hamcrest.StringDescription;
1312
import org.junit.AssumptionViolatedException;
@@ -168,7 +167,10 @@ public Statement apply(Statement base,
168167
* thrown.expect(is(e));
169168
* throw e;
170169
* }</pre>
170+
*
171+
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expect()}
171172
*/
173+
@Deprecated
172174
public void expect(Matcher<?> matcher) {
173175
matcherBuilder.add(matcher);
174176
}
@@ -207,7 +209,10 @@ public void expectMessage(String substring) {
207209
* thrown.expectMessage(startsWith(&quot;What&quot;));
208210
* throw new NullPointerException(&quot;What happened?&quot;);
209211
* }</pre>
212+
*
213+
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expectMessage()}
210214
*/
215+
@Deprecated
211216
public void expectMessage(Matcher<String> matcher) {
212217
expect(hasMessage(matcher));
213218
}
@@ -221,7 +226,10 @@ public void expectMessage(Matcher<String> matcher) {
221226
* thrown.expectCause(is(expectedCause));
222227
* throw new IllegalArgumentException(&quot;What happened?&quot;, cause);
223228
* }</pre>
229+
*
230+
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expectCause()}
224231
*/
232+
@Deprecated
225233
public void expectCause(Matcher<? extends Throwable> expectedCause) {
226234
expect(hasCause(expectedCause));
227235
}

0 commit comments

Comments
 (0)