1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import org .springframework .util .ObjectUtils ;
21
21
22
22
/**
23
- * JUnit independent assertion class .
23
+ * Test assertions that are independent of any third-party assertion library .
24
24
*
25
25
* @author Lukas Krecan
26
26
* @author Arjen Poutsma
27
+ * @author Sam Brannen
27
28
* @since 3.2
28
29
*/
29
30
public abstract class AssertionErrors {
30
31
31
32
/**
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
34
35
*/
35
36
public static void fail (String message ) {
36
37
throw new AssertionError (message );
37
38
}
38
39
39
40
/**
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
41
42
* values to be added to the message.
42
43
* <p>For example given:
43
44
* <pre class="code">
@@ -47,18 +48,18 @@ public static void fail(String message) {
47
48
* <pre class="code">
48
49
* Response header [Accept] expected:<application/json> but was:<text/plain>
49
50
* </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
53
54
*/
54
55
public static void fail (String message , @ Nullable Object expected , @ Nullable Object actual ) {
55
56
throw new AssertionError (message + " expected:<" + expected + "> but was:<" + actual + ">" );
56
57
}
57
58
58
59
/**
59
60
* 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
62
63
* @param condition the condition to test for
63
64
*/
64
65
public static void assertTrue (String message , boolean condition ) {
@@ -68,12 +69,23 @@ public static void assertTrue(String message, boolean condition) {
68
69
}
69
70
70
71
/**
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.
72
84
* <p>For example:
73
85
* <pre class="code">
74
86
* assertEquals("Response header [" + name + "]", expected, actual);
75
87
* </pre>
76
- * @param message describes the value being checked
88
+ * @param message a message that describes the reason for the failure
77
89
* @param expected the expected value
78
90
* @param actual the actual value
79
91
*/
@@ -89,7 +101,7 @@ public static void assertEquals(String message, @Nullable Object expected, @Null
89
101
* <pre class="code">
90
102
* assertNotEquals("Response header [" + name + "]", expected, actual);
91
103
* </pre>
92
- * @param message describes the value being checked
104
+ * @param message a message that describes the reason for the failure
93
105
* @param expected the expected value
94
106
* @param actual the actual value
95
107
*/
0 commit comments