1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2022 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.
16
16
17
17
package org .springframework .core .style ;
18
18
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 ;
23
20
import java .util .LinkedHashMap ;
24
21
import java .util .List ;
25
22
import java .util .Map ;
@@ -44,51 +41,38 @@ void styleBasics() throws NoSuchMethodException {
44
41
assertThat (styler .style ("str" )).isEqualTo ("'str'" );
45
42
assertThat (styler .style (String .class )).isEqualTo ("String" );
46
43
assertThat (styler .style (String .class .getMethod ("toString" ))).isEqualTo ("toString@String" );
44
+ assertThat (styler .style (String .class .getMethod ("getBytes" , Charset .class ))).isEqualTo ("getBytes@String" );
47
45
}
48
46
49
47
@ Test
50
48
void stylePlainObject () {
51
49
Object obj = new Object ();
52
-
53
50
assertThat (styler .style (obj )).isEqualTo (String .valueOf (obj ));
54
51
}
55
52
56
53
@ Test
57
54
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]" );
63
57
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
+ }};
67
62
assertThat (styler .style (map )).isEqualTo ("map['key1' -> 1, 'key2' -> 2]" );
68
63
}
69
64
70
65
@ Test
71
66
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" );
80
69
}
81
70
82
71
@ 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]" );
92
76
}
93
77
94
78
@ Test
0 commit comments