Skip to content

Commit f6110dd

Browse files
committed
Polishing
1 parent cd7c650 commit f6110dd

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ else if (obj != null) {
288288
}
289289

290290
/**
291-
* Convert the given array (which may be a primitive array) to an
292-
* object array (if necessary of primitive wrapper objects).
293-
* <p>A {@code null} source value will be converted to an
291+
* Convert the given array (which may be a primitive array) to an object array (if
292+
* necessary, to an array of primitive wrapper objects).
293+
* <p>A {@code null} source value or empty primitive array will be converted to an
294294
* empty Object array.
295295
* @param source the (potentially primitive) array
296296
* @return the corresponding object array (never {@code null})

spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,20 @@ void toObjectArrayWithEmptyPrimitiveArray() {
188188

189189
@Test
190190
void toObjectArrayWithNonArrayType() {
191-
assertThatIllegalArgumentException().isThrownBy(() ->
192-
ObjectUtils.toObjectArray("Not an []"));
191+
assertThatIllegalArgumentException()
192+
.isThrownBy(() -> ObjectUtils.toObjectArray("Not an []"))
193+
.withMessageStartingWith("Source is not an array");
193194
}
194195

195196
@Test
196197
void toObjectArrayWithNonPrimitiveArray() {
197-
String[] source = new String[] {"Bingo"};
198-
assertThat(ObjectUtils.toObjectArray(source)).isEqualTo(source);
198+
String[] source = {"Bingo"};
199+
assertThat(ObjectUtils.toObjectArray(source)).isSameAs(source);
199200
}
200201

201202
@Test
202203
void addObjectToArraySunnyDay() {
203-
String[] array = new String[] {"foo", "bar"};
204+
String[] array = {"foo", "bar"};
204205
String newElement = "baz";
205206
Object[] newArray = ObjectUtils.addObjectToArray(array, newElement);
206207
assertThat(newArray).hasSize(3);
@@ -209,7 +210,7 @@ void addObjectToArraySunnyDay() {
209210

210211
@Test
211212
void addObjectToArraysAtPosition() {
212-
String[] array = new String[] {"foo", "bar", "baz"};
213+
String[] array = {"foo", "bar", "baz"};
213214
assertThat(ObjectUtils.addObjectToArray(array, "bat", 3)).containsExactly("foo", "bar", "baz", "bat");
214215
assertThat(ObjectUtils.addObjectToArray(array, "bat", 2)).containsExactly("foo", "bar", "bat", "baz");
215216
assertThat(ObjectUtils.addObjectToArray(array, "bat", 1)).containsExactly("foo", "bat", "bar", "baz");
@@ -228,7 +229,7 @@ void addObjectToArrayWhenEmpty() {
228229
@Test
229230
void addObjectToSingleNonNullElementArray() {
230231
String existingElement = "foo";
231-
String[] array = new String[] {existingElement};
232+
String[] array = {existingElement};
232233
String newElement = "bar";
233234
String[] newArray = ObjectUtils.addObjectToArray(array, newElement);
234235
assertThat(newArray).hasSize(2);
@@ -238,7 +239,7 @@ void addObjectToSingleNonNullElementArray() {
238239

239240
@Test
240241
void addObjectToSingleNullElementArray() {
241-
String[] array = new String[] {null};
242+
String[] array = {null};
242243
String newElement = "bar";
243244
String[] newArray = ObjectUtils.addObjectToArray(array, newElement);
244245
assertThat(newArray).hasSize(2);

spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public MediaTypeAssert(@Nullable MediaType mediaType) {
5151
* representation.
5252
* @param mediaType the expected media type, as a String to be parsed
5353
* into a MediaType
54-
*/
54+
*/
5555
public MediaTypeAssert isEqualTo(String mediaType) {
5656
return isEqualTo(parseMediaType(mediaType));
5757
}

0 commit comments

Comments
 (0)