Skip to content

Commit

Permalink
Deprecate APIs that use Hamcrest classes. Users should use the java-h…
Browse files Browse the repository at this point in the history
…amcrest library instead.
  • Loading branch information
kcooney committed May 27, 2015
1 parent 4bef795 commit 53d6fc2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,9 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* values
* @see org.hamcrest.CoreMatchers
* @see org.hamcrest.MatcherAssert
* @deprecated use {@code org.hamcrest.junit.MatcherAssert.assertThat()}
*/
@Deprecated
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
assertThat("", actual, matcher);
}
Expand Down Expand Up @@ -950,7 +952,9 @@ public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
* values
* @see org.hamcrest.CoreMatchers
* @see org.hamcrest.MatcherAssert
* @deprecated use {@code org.hamcrest.junit.MatcherAssert.assertThat()}
*/
@Deprecated
public static <T> void assertThat(String reason, T actual,
Matcher<? super T> matcher) {
MatcherAssert.assertThat(reason, actual, matcher);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/junit/Assume.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public static void assumeNotNull(Object... objects) {
* @param matcher an expression, built of {@link Matcher}s, specifying allowed values
* @see org.hamcrest.CoreMatchers
* @see org.junit.matchers.JUnitMatchers
* @deprecated use {@code org.hamcrest.junit.MatcherAssume.assumeThat()}
*/
@Deprecated
public static <T> void assumeThat(T actual, Matcher<T> matcher) {
if (!matcher.matches(actual)) {
throw new AssumptionViolatedException(actual, matcher);
Expand All @@ -112,7 +114,9 @@ public static <T> void assumeThat(T actual, Matcher<T> matcher) {
* @param matcher an expression, built of {@link Matcher}s, specifying allowed values
* @see org.hamcrest.CoreMatchers
* @see org.junit.matchers.JUnitMatchers
* @deprecated use {@code org.hamcrest.junit.MatcherAssume.assumeThat()}
*/
@Deprecated
public static <T> void assumeThat(String message, T actual, Matcher<T> matcher) {
if (!matcher.matches(actual)) {
throw new AssumptionViolatedException(message, actual, matcher);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/junit/AssumptionViolatedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AssumptionViolatedException extends org.junit.internal.AssumptionVi
* An assumption exception with the given <i>actual</i> value and a <i>matcher</i> describing
* the expectation that failed.
*/
@Deprecated
public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
super(actual, matcher);
}
Expand All @@ -26,6 +27,7 @@ public <T> AssumptionViolatedException(T actual, Matcher<T> matcher) {
* An assumption exception with a message with the given <i>actual</i> value and a
* <i>matcher</i> describing the expectation that failed.
*/
@Deprecated
public <T> AssumptionViolatedException(String message, T expected, Matcher<T> matcher) {
super(message, expected, matcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
/**
* A matcher that delegates to throwableMatcher and in addition appends the
* stacktrace of the actual Throwable in case of a mismatch.
*
* @deprecated use {@code org.hamcrest.junit.JunitMatchers.isThrowable()}
* or {@code org.hamcrest.junit.JunitMatchers.isException()}
*/
@Deprecated
public class StacktracePrintingMatcher<T extends Throwable> extends
org.hamcrest.TypeSafeMatcher<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* match.
*
* @param <T> the type of the throwable being matched
* @deprecated use {@code org.hamcrest.junit.ExpectedException}
*/
@Deprecated
public class ThrowableCauseMatcher<T extends Throwable> extends
TypeSafeMatcher<T> {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/junit/matchers/JUnitMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* not currently included in the basic CoreMatchers class from hamcrest.
*
* @since 4.4
* @deprecated use {@code org.hamcrest.junit.JUnitMatchers}
*/
@Deprecated
public class JUnitMatchers {
/**
* @return A matcher matching any collection containing element
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/junit/rules/ErrorCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public void addError(Throwable error) {
/**
* Adds a failure to the table if {@code matcher} does not match {@code value}.
* Execution continues, but the test will fail at the end if the match fails.
*
* @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()}
*/
@Deprecated
public <T> void checkThat(final T value, final Matcher<T> matcher) {
checkThat("", value, matcher);
}
Expand All @@ -58,7 +61,10 @@ public <T> void checkThat(final T value, final Matcher<T> matcher) {
* Adds a failure with the given {@code reason}
* to the table if {@code matcher} does not match {@code value}.
* Execution continues, but the test will fail at the end if the match fails.
*
* @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()}
*/
@Deprecated
public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) {
checkSucceeds(new Callable<Object>() {
public Object call() throws Exception {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/junit/rules/ExpectedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.junit.Assert.fail;
import static org.junit.internal.matchers.ThrowableCauseMatcher.hasCause;
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;

import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AssumptionViolatedException;
Expand Down Expand Up @@ -168,7 +167,10 @@ public Statement apply(Statement base,
* thrown.expect(is(e));
* throw e;
* }</pre>
*
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expect()}
*/
@Deprecated
public void expect(Matcher<?> matcher) {
matcherBuilder.add(matcher);
}
Expand Down Expand Up @@ -207,7 +209,10 @@ public void expectMessage(String substring) {
* thrown.expectMessage(startsWith(&quot;What&quot;));
* throw new NullPointerException(&quot;What happened?&quot;);
* }</pre>
*
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expectMessage()}
*/
@Deprecated
public void expectMessage(Matcher<String> matcher) {
expect(hasMessage(matcher));
}
Expand All @@ -221,7 +226,10 @@ public void expectMessage(Matcher<String> matcher) {
* thrown.expectCause(is(expectedCause));
* throw new IllegalArgumentException(&quot;What happened?&quot;, cause);
* }</pre>
*
* @deprecated use {@code org.hamcrest.junit.ExpectedException.expectCause()}
*/
@Deprecated
public void expectCause(Matcher<? extends Throwable> expectedCause) {
expect(hasCause(expectedCause));
}
Expand Down

0 comments on commit 53d6fc2

Please sign in to comment.