16
16
17
17
package org .springframework .test .json ;
18
18
19
- import java .lang .reflect .Array ;
20
19
import java .lang .reflect .Type ;
21
20
import java .util .List ;
22
21
import java .util .Map ;
43
42
44
43
/**
45
44
* Base AssertJ {@link org.assertj.core.api.Assert assertions} that can be
46
- * applied to a JSON value. In JSON, values must be one of the following data
47
- * types:
45
+ * applied to a JSON value.
46
+ *
47
+ * <p>In JSON, values must be one of the following data types:
48
48
* <ul>
49
49
* <li>a {@linkplain #asString() string}</li>
50
50
* <li>a {@linkplain #asNumber() number}</li>
53
53
* <li>an {@linkplain #asMap() object} (JSON object)</li>
54
54
* <li>{@linkplain #isNull() null}</li>
55
55
* </ul>
56
- * This base class offers direct access for each of those types as well as a
56
+ * This base class offers direct access for each of those types as well as
57
57
* conversion methods based on an optional {@link GenericHttpMessageConverter}.
58
58
*
59
59
* @author Stephane Nicoll
@@ -71,12 +71,14 @@ public abstract class AbstractJsonValueAssert<SELF extends AbstractJsonValueAsse
71
71
72
72
protected AbstractJsonValueAssert (@ Nullable Object actual , Class <?> selfType ,
73
73
@ Nullable GenericHttpMessageConverter <Object > httpMessageConverter ) {
74
+
74
75
super (actual , selfType );
75
76
this .httpMessageConverter = httpMessageConverter ;
76
77
}
77
78
79
+
78
80
/**
79
- * Verify that the actual value is a non-{@code null} {@link String}
81
+ * Verify that the actual value is a non-{@code null} {@link String},
80
82
* and return a new {@linkplain AbstractStringAssert assertion} object that
81
83
* provides dedicated {@code String} assertions for it.
82
84
*/
@@ -87,15 +89,15 @@ public AbstractStringAssert<?> asString() {
87
89
88
90
/**
89
91
* Verify that the actual value is a non-{@code null} {@link Number},
90
- * usually an {@link Integer} or {@link Double} and return a new
92
+ * usually an {@link Integer} or {@link Double}, and return a new
91
93
* {@linkplain AbstractObjectAssert assertion} object for it.
92
94
*/
93
95
public AbstractObjectAssert <?, Number > asNumber () {
94
96
return Assertions .assertThat (castTo (Number .class , "a number" ));
95
97
}
96
98
97
99
/**
98
- * Verify that the actual value is a non-{@code null} {@link Boolean}
100
+ * Verify that the actual value is a non-{@code null} {@link Boolean},
99
101
* and return a new {@linkplain AbstractBooleanAssert assertion} object
100
102
* that provides dedicated {@code Boolean} assertions for it.
101
103
*/
@@ -104,9 +106,9 @@ public AbstractBooleanAssert<?> asBoolean() {
104
106
}
105
107
106
108
/**
107
- * Verify that the actual value is a non-{@code null} {@link Array}
108
- * and return a new {@linkplain ObjectArrayAssert assertion} object
109
- * that provides dedicated {@code Array} assertions for it.
109
+ * Verify that the actual value is a non-{@code null} array, and return a
110
+ * new {@linkplain ObjectArrayAssert assertion} object that provides dedicated
111
+ * array assertions for it.
110
112
*/
111
113
public ObjectArrayAssert <Object > asArray () {
112
114
List <?> list = castTo (List .class , "an array" );
@@ -115,11 +117,12 @@ public ObjectArrayAssert<Object> asArray() {
115
117
}
116
118
117
119
/**
118
- * Verify that the actual value is a non-{@code null} JSON object and
120
+ * Verify that the actual value is a non-{@code null} JSON object, and
119
121
* return a new {@linkplain AbstractMapAssert assertion} object that
120
122
* provides dedicated assertions on individual elements of the
121
- * object. The returned map assertion object uses the attribute name as the
122
- * key, and the value can itself be any of the valid JSON values.
123
+ * object.
124
+ * <p>The returned map assertion object uses attribute names as the keys,
125
+ * and the values can be any of the valid JSON values.
123
126
*/
124
127
@ SuppressWarnings ("unchecked" )
125
128
public AbstractMapAssert <?, Map <String , Object >, String , Object > asMap () {
@@ -138,7 +141,7 @@ private <T> T castTo(Class<T> expectedType, String description) {
138
141
139
142
/**
140
143
* Verify that the actual value can be converted to an instance of the
141
- * given {@code target} and produce a new {@linkplain AbstractObjectAssert
144
+ * given {@code target}, and produce a new {@linkplain AbstractObjectAssert
142
145
* assertion} object narrowed to that type.
143
146
* @param target the {@linkplain Class type} to convert the actual value to
144
147
*/
@@ -150,7 +153,7 @@ public <T> AbstractObjectAssert<?, T> convertTo(Class<T> target) {
150
153
151
154
/**
152
155
* Verify that the actual value can be converted to an instance of the
153
- * given {@code target} and produce a new {@linkplain AbstractObjectAssert
156
+ * given {@code target}, and produce a new {@linkplain AbstractObjectAssert
154
157
* assertion} object narrowed to that type.
155
158
* @param target the {@linkplain ParameterizedTypeReference parameterized
156
159
* type} to convert the actual value to
@@ -162,9 +165,10 @@ public <T> AbstractObjectAssert<?, T> convertTo(ParameterizedTypeReference<T> ta
162
165
}
163
166
164
167
/**
165
- * Verify that the actual value is empty, that is a {@code null} scalar
166
- * value or an empty list or map. Can also be used when the path is using a
167
- * filter operator to validate that it dit not match.
168
+ * Verify that the actual value is empty: either a {@code null} scalar value
169
+ * or an empty list or map.
170
+ * <p>Can also be used when the path uses a filter operator to validate that
171
+ * it did not match.
168
172
*/
169
173
public SELF isEmpty () {
170
174
if (!ObjectUtils .isEmpty (this .actual )) {
@@ -174,10 +178,10 @@ public SELF isEmpty() {
174
178
}
175
179
176
180
/**
177
- * Verify that the actual value is not empty, that is a non-{@code null}
178
- * scalar value or a non-empty list or map. Can also be used when the path is
179
- * using a filter operator to validate that it dit match at least one
180
- * element.
181
+ * Verify that the actual value is not empty: either a non-{@code null}
182
+ * scalar value or a non-empty list or map.
183
+ * <p>Can also be used when the path uses a filter operator to validate that
184
+ * it did match at least one element.
181
185
*/
182
186
public SELF isNotEmpty () {
183
187
if (ObjectUtils .isEmpty (this .actual )) {
@@ -225,6 +229,7 @@ private String actualToString() {
225
229
return ObjectUtils .nullSafeToString (StringUtils .quoteIfString (this .actual ));
226
230
}
227
231
232
+
228
233
private static final class ValueProcessingFailed extends BasicErrorMessageFactory {
229
234
230
235
private ValueProcessingFailed (String prefix , String actualToString , String errorMessage ) {
0 commit comments