16
16
17
17
package org .springframework .boot .actuate .autoconfigure .metrics ;
18
18
19
- import java .util .Collections ;
20
19
import java .util .Map ;
21
- import java .util .stream .Stream ;
22
20
23
21
import org .junit .jupiter .api .Test ;
24
- import org .junit .jupiter .params .ParameterizedTest ;
25
- import org .junit .jupiter .params .provider .Arguments ;
26
- import org .junit .jupiter .params .provider .MethodSource ;
27
22
28
23
import org .springframework .data .util .Pair ;
29
- import org .springframework .test .util .ReflectionTestUtils ;
30
24
31
25
import static org .assertj .core .api .Assertions .assertThat ;
32
26
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
@@ -35,44 +29,16 @@ class SpelTagValueExpressionResolverTests {
35
29
36
30
final SpelTagValueExpressionResolver resolver = new SpelTagValueExpressionResolver ();
37
31
38
- @ ParameterizedTest
39
- @ MethodSource
40
- void checkValidExpression (Object value , String expression , String expected ) {
41
- assertThat (this .resolver .resolve (expression , value )).isEqualTo (expected );
42
- }
43
-
44
- static Stream <Arguments > checkValidExpression () {
45
- return Stream .of (Arguments .of ("foo" , "length" , "3" ), Arguments .of ("foo" , "isEmpty" , "false" ),
46
- Arguments .of (Pair .of ("left" , "right" ), "first" , "left" ),
47
- Arguments .of (Map .of ("foo" , "bar" ), "['foo']" , "bar" ),
48
- Arguments .of (Map .of ("foo" , "bar" ), "['baz']" , null ),
49
- Arguments .of (Map .of ("foo" , Pair .of (1 , 2 )), "['foo'].first" , "1" ),
50
- Arguments .of (Map .of ("foo" , Pair .of (1 , 2 )), "['bar']?.first" , null ));
51
- }
52
-
53
- @ ParameterizedTest
54
- @ MethodSource
55
- void checkInvalidExpression (Object value , String expression ) {
56
- assertThatIllegalStateException ().isThrownBy (() -> this .resolver .resolve (expression , value ));
57
- }
58
-
59
- static Stream <Arguments > checkInvalidExpression () {
60
- return Stream .of (Arguments .of ("foo" , "unknownMethod" ), Arguments .of (null , "length" ),
61
- Arguments .of (Map .of ("foo" , Pair .of (1 , 2 )), "['bar'].first" ),
62
- Arguments .of (Collections .emptyMap (), "invalid expression" ));
32
+ @ Test
33
+ void checkValidExpression () {
34
+ var value = Map .of ("foo" , Pair .of (1 , 2 ));
35
+ assertThat (this .resolver .resolve ("['foo'].first" , value )).isEqualTo ("1" );
63
36
}
64
37
65
38
@ Test
66
- void checkParserReuse () {
67
- var map = (Map <?, ?>) ReflectionTestUtils .getField (this .resolver , "expressionMap" );
68
-
69
- this .resolver .resolve ("length" , "foo" );
70
- this .resolver .resolve ("length" , "bar" );
71
-
72
- assertThat (map ).hasSize (1 );
73
-
74
- this .resolver .resolve ("isEmpty" , "foo" );
75
- assertThat (map ).hasSize (2 );
39
+ void checkInvalidExpression () {
40
+ var value = Map .of ("foo" , Pair .of (1 , 2 ));
41
+ assertThatIllegalStateException ().isThrownBy (() -> this .resolver .resolve ("['bar'].first" , value ));
76
42
}
77
43
78
44
}
0 commit comments