21
21
import java .util .Properties ;
22
22
import java .util .function .Consumer ;
23
23
import java .util .function .Function ;
24
- import java .util .stream .Stream ;
25
24
26
25
import org .junit .jupiter .api .Test ;
27
26
32
31
* Tests for {@link ProxyHints}.
33
32
*
34
33
* @author Stephane Nicoll
34
+ * @author Sam Brannen
35
35
*/
36
36
class ProxyHintsTests {
37
37
@@ -51,16 +51,15 @@ void registerJdkProxyWithConcreteClass() {
51
51
}
52
52
53
53
@ Test
54
- void registerJdkProxyWithInterfaceClassNames () {
55
- this .proxyHints .registerJdkProxy (TypeReference .of (Function .class ),
56
- TypeReference .of ("com.example.Advised" ));
57
- assertThat (this .proxyHints .jdkProxies ()).singleElement ().satisfies (proxiedInterfaces (
58
- Function .class .getName (), "com.example.Advised" ));
54
+ void registerJdkProxyWithTypeReferences () {
55
+ this .proxyHints .registerJdkProxy (TypeReference .of (Function .class ), TypeReference .of ("com.example.Advised" ));
56
+ assertThat (this .proxyHints .jdkProxies ()).singleElement ()
57
+ .satisfies (proxiedInterfaces (Function .class .getName (), "com.example.Advised" ));
59
58
}
60
59
61
60
@ Test
62
61
void registerJdkProxyWithConsumer () {
63
- this .proxyHints .registerJdkProxy (springProxy (TypeReference . of ( "com.example.Test" ) ));
62
+ this .proxyHints .registerJdkProxy (springProxy ("com.example.Test" ));
64
63
assertThat (this .proxyHints .jdkProxies ()).singleElement ().satisfies (proxiedInterfaces (
65
64
"com.example.Test" ,
66
65
"org.springframework.aop.SpringProxy" ,
@@ -97,28 +96,36 @@ void registerClassProxyWithTargetClass() {
97
96
98
97
@ Test
99
98
void registerClassProxyWithTargetInterface () {
100
- assertThatIllegalArgumentException ().isThrownBy (() -> this .proxyHints .registerClassProxy (Serializable .class , classProxyHint -> {
101
- })).withMessageContaining (Serializable .class .getName ());
99
+ assertThatIllegalArgumentException ()
100
+ .isThrownBy (() -> this .proxyHints .registerClassProxy (Serializable .class , classProxyHint -> {}))
101
+ .withMessageContaining (Serializable .class .getName ());
102
102
}
103
103
104
- private static Consumer <JdkProxyHint .Builder > springProxy (TypeReference proxiedInterface ) {
105
- return builder -> builder
106
- .proxiedInterfaces (proxiedInterface )
107
- .proxiedInterfaces (Stream .of ("org.springframework.aop.SpringProxy" ,
108
- "org.springframework.aop.framework.Advised" , "org.springframework.core.DecoratingProxy" )
109
- .map (TypeReference ::of ).toArray (TypeReference []::new ));
104
+
105
+ private static Consumer <JdkProxyHint .Builder > springProxy (String proxiedInterface ) {
106
+ return builder -> builder .proxiedInterfaces (toTypeReferences (
107
+ proxiedInterface ,
108
+ "org.springframework.aop.SpringProxy" ,
109
+ "org.springframework.aop.framework.Advised" ,
110
+ "org.springframework.core.DecoratingProxy" ));
110
111
}
111
112
112
- private Consumer <JdkProxyHint > proxiedInterfaces (String ... proxiedInterfaces ) {
113
+ private static Consumer <JdkProxyHint > proxiedInterfaces (String ... proxiedInterfaces ) {
113
114
return jdkProxyHint -> assertThat (jdkProxyHint .getProxiedInterfaces ())
114
- .containsExactly (Arrays .stream (proxiedInterfaces )
115
- .map (TypeReference ::of ).toArray (TypeReference []::new ));
115
+ .containsExactly (toTypeReferences (proxiedInterfaces ));
116
116
}
117
117
118
- private Consumer <JdkProxyHint > proxiedInterfaces (Class <?>... proxiedInterfaces ) {
118
+ private static Consumer <JdkProxyHint > proxiedInterfaces (Class <?>... proxiedInterfaces ) {
119
119
return jdkProxyHint -> assertThat (jdkProxyHint .getProxiedInterfaces ())
120
- .containsExactly (Arrays .stream (proxiedInterfaces )
121
- .map (TypeReference ::of ).toArray (TypeReference []::new ));
120
+ .containsExactly (toTypeReferences (proxiedInterfaces ));
121
+ }
122
+
123
+ private static TypeReference [] toTypeReferences (String ... proxiedInterfaces ) {
124
+ return Arrays .stream (proxiedInterfaces ).map (TypeReference ::of ).toArray (TypeReference []::new );
125
+ }
126
+
127
+ private static TypeReference [] toTypeReferences (Class <?>... proxiedInterfaces ) {
128
+ return Arrays .stream (proxiedInterfaces ).map (TypeReference ::of ).toArray (TypeReference []::new );
122
129
}
123
130
124
131
}
0 commit comments