Remove dependency on hamcrest-lib from spring-mvc-test
The change removes the use of concrete Matcher implementations and thus the dependency on hamcrest-lib leaving hamcrest-core as the only (optional) hamcrest dependency. Issue: SPR-9961
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.test.util;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* JUnit independent assertion class.
|
||||
*
|
||||
@@ -24,13 +26,14 @@ package org.springframework.test.util;
|
||||
*/
|
||||
public abstract class AssertionErrors {
|
||||
|
||||
|
||||
private AssertionErrors() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails a test with the given message.
|
||||
*
|
||||
* @param message the message
|
||||
* @param message describes the reason for the failure
|
||||
*/
|
||||
public static void fail(String message) {
|
||||
throw new AssertionError(message);
|
||||
@@ -40,17 +43,26 @@ public abstract class AssertionErrors {
|
||||
* Fails a test with the given message passing along expected and actual
|
||||
* values to be added to the message.
|
||||
*
|
||||
* @param message the message
|
||||
* @param expected the expected value
|
||||
* @param actual the actual value
|
||||
* <p>For example given:
|
||||
* <pre>
|
||||
* assertEquals("Response header [" + name + "]", actual, expected);
|
||||
* </pre>
|
||||
* <p>The resulting message is:
|
||||
* <pre>
|
||||
* Response header [Accept] expected:<application/json> but was:<text/plain>
|
||||
* </pre>
|
||||
*
|
||||
* @param message describes the value that failed the match
|
||||
* @param expected expected value
|
||||
* @param actual actual value
|
||||
*/
|
||||
public static void fail(String message, Object expected, Object actual) {
|
||||
throw new AssertionError(message + " expected:<" + expected + "> but was:<" + actual + ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is {@code true}. If not, throws an
|
||||
* {@link AssertionError} with the given message.
|
||||
* Assert the given condition is {@code true} and raise an
|
||||
* {@link AssertionError} if it is not.
|
||||
*
|
||||
* @param message the message
|
||||
* @param condition the condition to test for
|
||||
@@ -62,21 +74,20 @@ public abstract class AssertionErrors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects are equal. If not, an {@link AssertionError} is
|
||||
* thrown with the given message.
|
||||
* Assert two objects are equal raise an {@link AssertionError} if not.
|
||||
* <p>For example:
|
||||
* <pre>
|
||||
* assertEquals("Response header [" + name + "]", actual, expected);
|
||||
* </pre>
|
||||
*
|
||||
* @param message the message
|
||||
* @param message describes the value being checked
|
||||
* @param expected the expected value
|
||||
* @param actual the actual value
|
||||
*/
|
||||
public static void assertEquals(String message, Object expected, Object actual) {
|
||||
if (expected == null && actual == null) {
|
||||
return;
|
||||
}
|
||||
if (expected != null && expected.equals(actual)) {
|
||||
return;
|
||||
}
|
||||
fail(message, expected, actual);
|
||||
if (!ObjectUtils.nullSafeEquals(expected, actual)) {
|
||||
fail(message, expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user