|
30 | 30 | import java.sql.SQLException;
|
31 | 31 | import java.time.LocalDate;
|
32 | 32 | import java.time.ZoneId;
|
33 |
| -import java.util.ArrayList; |
34 | 33 | import java.util.Collections;
|
35 | 34 | import java.util.Currency;
|
36 | 35 | import java.util.Date;
|
@@ -1034,19 +1033,47 @@ void nullSafeConciseToStringForZoneId() {
|
1034 | 1033 | }
|
1035 | 1034 |
|
1036 | 1035 | @Test
|
1037 |
| - void nullSafeConciseToStringForArraysAndCollections() { |
1038 |
| - List<String> list = List.of("a", "b", "c"); |
1039 |
| - assertThat(ObjectUtils.nullSafeConciseToString(new int[][] {{1, 2}, {3, 4}})).startsWith(prefix(int[][].class)); |
1040 |
| - assertThat(ObjectUtils.nullSafeConciseToString(list.toArray())).startsWith(prefix(Object[].class)); |
1041 |
| - assertThat(ObjectUtils.nullSafeConciseToString(list.toArray(String[]::new))).startsWith(prefix(String[].class)); |
1042 |
| - assertThat(ObjectUtils.nullSafeConciseToString(new ArrayList<>(list))).startsWith(prefix(ArrayList.class)); |
1043 |
| - assertThat(ObjectUtils.nullSafeConciseToString(new HashSet<>(list))).startsWith(prefix(HashSet.class)); |
| 1036 | + void nullSafeConciseToStringForEmptyArrays() { |
| 1037 | + assertThat(ObjectUtils.nullSafeConciseToString(new char[] {})).isEqualTo("{}"); |
| 1038 | + assertThat(ObjectUtils.nullSafeConciseToString(new int[][] {})).isEqualTo("{}"); |
| 1039 | + assertThat(ObjectUtils.nullSafeConciseToString(new String[] {})).isEqualTo("{}"); |
| 1040 | + assertThat(ObjectUtils.nullSafeConciseToString(new Integer[][] {})).isEqualTo("{}"); |
1044 | 1041 | }
|
1045 | 1042 |
|
1046 | 1043 | @Test
|
1047 |
| - void nullSafeConciseToStringForMaps() { |
| 1044 | + void nullSafeConciseToStringForNonEmptyArrays() { |
| 1045 | + assertThat(ObjectUtils.nullSafeConciseToString(new char[] {'a'})).isEqualTo("{...}"); |
| 1046 | + assertThat(ObjectUtils.nullSafeConciseToString(new int[][] {{1}, {2}})).isEqualTo("{...}"); |
| 1047 | + assertThat(ObjectUtils.nullSafeConciseToString(new String[] {"enigma"})).isEqualTo("{...}"); |
| 1048 | + assertThat(ObjectUtils.nullSafeConciseToString(new Integer[][] {{1}, {2}})).isEqualTo("{...}"); |
| 1049 | + } |
| 1050 | + |
| 1051 | + @Test |
| 1052 | + void nullSafeConciseToStringForEmptyCollections() { |
| 1053 | + List<String> list = List.of(); |
| 1054 | + Set<Integer> set = Set.of(); |
| 1055 | + assertThat(ObjectUtils.nullSafeConciseToString(list)).isEqualTo("[]"); |
| 1056 | + assertThat(ObjectUtils.nullSafeConciseToString(set)).isEqualTo("[]"); |
| 1057 | + } |
| 1058 | + |
| 1059 | + @Test |
| 1060 | + void nullSafeConciseToStringForNonEmptyCollections() { |
| 1061 | + List<String> list = List.of("a", "b"); |
| 1062 | + Set<Integer> set = Set.of(1); |
| 1063 | + assertThat(ObjectUtils.nullSafeConciseToString(list)).isEqualTo("[...]"); |
| 1064 | + assertThat(ObjectUtils.nullSafeConciseToString(set)).isEqualTo("[...]"); |
| 1065 | + } |
| 1066 | + |
| 1067 | + @Test |
| 1068 | + void nullSafeConciseToStringForEmptyMaps() { |
| 1069 | + Map<String, String> map = new HashMap<String, String>(); |
| 1070 | + assertThat(ObjectUtils.nullSafeConciseToString(map)).isEqualTo("{}"); |
| 1071 | + } |
| 1072 | + |
| 1073 | + @Test |
| 1074 | + void nullSafeConciseToStringForNonEmptyMaps() { |
1048 | 1075 | Map<String, Integer> map = Map.of("a", 1, "b", 2, "c", 3);
|
1049 |
| - assertThat(ObjectUtils.nullSafeConciseToString(map)).startsWith(prefix(map.getClass())); |
| 1076 | + assertThat(ObjectUtils.nullSafeConciseToString(map)).isEqualTo("{...}"); |
1050 | 1077 | }
|
1051 | 1078 |
|
1052 | 1079 | @Test
|
|
0 commit comments