Skip to content

Commit 7f4dbdb

Browse files
committed
Polish DefaultValueStylerTests
1 parent 5070604 commit 7f4dbdb

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

spring-core/src/test/java/org/springframework/core/style/DefaultValueStylerTests.java

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -16,10 +16,7 @@
1616

1717
package org.springframework.core.style;
1818

19-
import java.util.Arrays;
20-
import java.util.Collections;
21-
import java.util.HashMap;
22-
import java.util.Iterator;
19+
import java.nio.charset.Charset;
2320
import java.util.LinkedHashMap;
2421
import java.util.List;
2522
import java.util.Map;
@@ -44,51 +41,38 @@ void styleBasics() throws NoSuchMethodException {
4441
assertThat(styler.style("str")).isEqualTo("'str'");
4542
assertThat(styler.style(String.class)).isEqualTo("String");
4643
assertThat(styler.style(String.class.getMethod("toString"))).isEqualTo("toString@String");
44+
assertThat(styler.style(String.class.getMethod("getBytes", Charset.class))).isEqualTo("getBytes@String");
4745
}
4846

4947
@Test
5048
void stylePlainObject() {
5149
Object obj = new Object();
52-
5350
assertThat(styler.style(obj)).isEqualTo(String.valueOf(obj));
5451
}
5552

5653
@Test
5754
void styleMaps() {
58-
Map<String, Integer> map = Collections.emptyMap();
59-
assertThat(styler.style(map)).isEqualTo("map[[empty]]");
60-
61-
map = Collections.singletonMap("key", 1);
62-
assertThat(styler.style(map)).isEqualTo("map['key' -> 1]");
55+
assertThat(styler.style(Map.of())).isEqualTo("map[[empty]]");
56+
assertThat(styler.style(Map.of("key", 1))).isEqualTo("map['key' -> 1]");
6357

64-
map = new HashMap<>();
65-
map.put("key1", 1);
66-
map.put("key2", 2);
58+
Map<String, Integer> map = new LinkedHashMap<>() {{
59+
put("key1", 1);
60+
put("key2", 2);
61+
}};
6762
assertThat(styler.style(map)).isEqualTo("map['key1' -> 1, 'key2' -> 2]");
6863
}
6964

7065
@Test
7166
void styleMapEntries() {
72-
Map<String, Integer> map = new LinkedHashMap<>();
73-
map.put("key1", 1);
74-
map.put("key2", 2);
75-
76-
Iterator<Map.Entry<String, Integer>> entries = map.entrySet().iterator();
77-
78-
assertThat(styler.style(entries.next())).isEqualTo("'key1' -> 1");
79-
assertThat(styler.style(entries.next())).isEqualTo("'key2' -> 2");
67+
Map<String, Integer> map = Map.of("key1", 1, "key2", 2);
68+
assertThat(map.entrySet()).map(styler::style).containsExactlyInAnyOrder("'key1' -> 1", "'key2' -> 2");
8069
}
8170

8271
@Test
83-
void styleCollections() {
84-
List<Integer> list = Collections.emptyList();
85-
assertThat(styler.style(list)).isEqualTo("list[[empty]]");
86-
87-
list = Collections.singletonList(1);
88-
assertThat(styler.style(list)).isEqualTo("list[1]");
89-
90-
list = Arrays.asList(1, 2);
91-
assertThat(styler.style(list)).isEqualTo("list[1, 2]");
72+
void styleLists() {
73+
assertThat(styler.style(List.of())).isEqualTo("list[[empty]]");
74+
assertThat(styler.style(List.of(1))).isEqualTo("list[1]");
75+
assertThat(styler.style(List.of(1, 2))).isEqualTo("list[1, 2]");
9276
}
9377

9478
@Test

0 commit comments

Comments
 (0)