Skip to content

Commit 233b225

Browse files
committed
Remove JUnit dependency from HeaderResultMatchers
Prior to this commit, HeaderResultMatchers had a direct dependency on org.junit.Assert which forces JUnit 4 to be present on the classpath. This commit fixes this by introducing assertNotNull() in org.springframework.test.util.AssertionErrors and delegating to that instead. Fixes gh-22932
1 parent 8c77d0b commit 233b225

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

spring-test/src/main/java/org/springframework/test/util/AssertionErrors.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,24 +20,25 @@
2020
import org.springframework.util.ObjectUtils;
2121

2222
/**
23-
* JUnit independent assertion class.
23+
* Test assertions that are independent of any third-party assertion library.
2424
*
2525
* @author Lukas Krecan
2626
* @author Arjen Poutsma
27+
* @author Sam Brannen
2728
* @since 3.2
2829
*/
2930
public abstract class AssertionErrors {
3031

3132
/**
32-
* Fails a test with the given message.
33-
* @param message describes the reason for the failure
33+
* Fail a test with the given message.
34+
* @param message a message that describes the reason for the failure
3435
*/
3536
public static void fail(String message) {
3637
throw new AssertionError(message);
3738
}
3839

3940
/**
40-
* Fails a test with the given message passing along expected and actual
41+
* Fail a test with the given message passing along expected and actual
4142
* values to be added to the message.
4243
* <p>For example given:
4344
* <pre class="code">
@@ -47,18 +48,18 @@ public static void fail(String message) {
4748
* <pre class="code">
4849
* Response header [Accept] expected:&lt;application/json&gt; but was:&lt;text/plain&gt;
4950
* </pre>
50-
* @param message describes the value that failed the match
51-
* @param expected expected value
52-
* @param actual actual value
51+
* @param message a message describes the value that failed the match
52+
* @param expected the expected value
53+
* @param actual the actual value
5354
*/
5455
public static void fail(String message, @Nullable Object expected, @Nullable Object actual) {
5556
throw new AssertionError(message + " expected:<" + expected + "> but was:<" + actual + ">");
5657
}
5758

5859
/**
5960
* Assert the given condition is {@code true} and raise an
60-
* {@link AssertionError} if it is not.
61-
* @param message the message
61+
* {@link AssertionError} otherwise.
62+
* @param message a message that describes the reason for the failure
6263
* @param condition the condition to test for
6364
*/
6465
public static void assertTrue(String message, boolean condition) {
@@ -68,12 +69,23 @@ public static void assertTrue(String message, boolean condition) {
6869
}
6970

7071
/**
71-
* Assert two objects are equal and raise an {@link AssertionError} if not.
72+
* Assert that the given object is not {@code null} and raise an
73+
* {@link AssertionError} otherwise.
74+
* @param message a message that describes the reason for the failure
75+
* @param object the object to check
76+
* @since 5.1
77+
*/
78+
public static void assertNotNull(String message, Object object) {
79+
assertTrue(message, object != null);
80+
}
81+
82+
/**
83+
* Assert two objects are equal and raise an {@link AssertionError} otherwise.
7284
* <p>For example:
7385
* <pre class="code">
7486
* assertEquals("Response header [" + name + "]", expected, actual);
7587
* </pre>
76-
* @param message describes the value being checked
88+
* @param message a message that describes the reason for the failure
7789
* @param expected the expected value
7890
* @param actual the actual value
7991
*/
@@ -89,7 +101,7 @@ public static void assertEquals(String message, @Nullable Object expected, @Null
89101
* <pre class="code">
90102
* assertNotEquals("Response header [" + name + "]", expected, actual);
91103
* </pre>
92-
* @param message describes the value being checked
104+
* @param message a message that describes the reason for the failure
93105
* @param expected the expected value
94106
* @param actual the actual value
95107
*/

spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@
2626
import org.springframework.test.web.servlet.ResultMatcher;
2727

2828
import static org.hamcrest.MatcherAssert.assertThat;
29-
import static org.junit.Assert.assertNotNull;
3029
import static org.springframework.test.util.AssertionErrors.assertEquals;
30+
import static org.springframework.test.util.AssertionErrors.assertNotNull;
3131
import static org.springframework.test.util.AssertionErrors.assertTrue;
3232

3333
/**

0 commit comments

Comments
 (0)