AssertionErrors.assertEquals exposes readable array representation
Issue: SPR-14281
This commit is contained in:
parent
86557f25af
commit
822e40e24f
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.util;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
@ -26,13 +27,8 @@ import org.springframework.util.ObjectUtils;
|
|||
*/
|
||||
public abstract class AssertionErrors {
|
||||
|
||||
|
||||
private AssertionErrors() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails a test with the given message.
|
||||
*
|
||||
* @param message describes the reason for the failure
|
||||
*/
|
||||
public static void fail(String message) {
|
||||
|
@ -42,7 +38,6 @@ public abstract class AssertionErrors {
|
|||
/**
|
||||
* Fails a test with the given message passing along expected and actual
|
||||
* values to be added to the message.
|
||||
*
|
||||
* <p>For example given:
|
||||
* <pre class="code">
|
||||
* assertEquals("Response header [" + name + "]", actual, expected);
|
||||
|
@ -51,7 +46,6 @@ public abstract class AssertionErrors {
|
|||
* <pre class="code">
|
||||
* 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
|
||||
|
@ -63,7 +57,6 @@ public abstract class AssertionErrors {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -79,14 +72,13 @@ public abstract class AssertionErrors {
|
|||
* <pre class="code">
|
||||
* assertEquals("Response header [" + name + "]", actual, expected);
|
||||
* </pre>
|
||||
*
|
||||
* @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 (!ObjectUtils.nullSafeEquals(expected, actual)) {
|
||||
fail(message, expected, actual);
|
||||
fail(message, ObjectUtils.nullSafeToString(expected), ObjectUtils.nullSafeToString(actual));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.springframework.util.MultiValueMap;
|
|||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.springframework.test.util.AssertionErrors.*;
|
||||
|
||||
|
||||
/**
|
||||
* Factory for request content {@code RequestMatcher}'s. An instance of this
|
||||
* class is typically accessed via {@link MockRestRequestMatchers#content()}.
|
||||
|
@ -145,6 +144,7 @@ public class ContentRequestMatchers {
|
|||
|
||||
/**
|
||||
* Parse the body as form data and compare to the given {@code MultiValueMap}.
|
||||
* @since 4.3
|
||||
*/
|
||||
public RequestMatcher formData(final MultiValueMap<String, String> expectedContent) {
|
||||
return new RequestMatcher() {
|
||||
|
@ -171,10 +171,8 @@ public class ContentRequestMatchers {
|
|||
* Parse the request body and the given String as XML and assert that the
|
||||
* two are "similar" - i.e. they contain the same elements and attributes
|
||||
* regardless of order.
|
||||
*
|
||||
* <p>Use of this matcher assumes the
|
||||
* <a href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library is available.
|
||||
*
|
||||
* @param expectedXmlContent the expected XML content
|
||||
*/
|
||||
public RequestMatcher xml(final String expectedXmlContent) {
|
||||
|
@ -211,6 +209,7 @@ public class ContentRequestMatchers {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for XML {@link RequestMatcher}'s.
|
||||
*/
|
||||
|
@ -222,12 +221,13 @@ public class ContentRequestMatchers {
|
|||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||
matchInternal(mockRequest);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AssertionError("Failed to parse expected or actual XML request content: " + e.getMessage());
|
||||
catch (Exception ex) {
|
||||
throw new AssertionError("Failed to parse expected or actual XML request content: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void matchInternal(MockClientHttpRequest request) throws Exception;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.springframework.util.MultiValueMap;
|
|||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ContentRequestMatchers}.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue