1616
1717package org .springframework .boot .actuate .autoconfigure .metrics ;
1818
19- import java .util .Collections ;
2019import java .util .Map ;
21- import java .util .stream .Stream ;
2220
2321import 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 ;
2722
2823import org .springframework .data .util .Pair ;
29- import org .springframework .test .util .ReflectionTestUtils ;
3024
3125import static org .assertj .core .api .Assertions .assertThat ;
3226import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
@@ -35,44 +29,16 @@ class SpelTagValueExpressionResolverTests {
3529
3630 final SpelTagValueExpressionResolver resolver = new SpelTagValueExpressionResolver ();
3731
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" );
6336 }
6437
6538 @ 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 ));
7642 }
7743
7844}
0 commit comments