Skip to content

Commit 5c2ee24

Browse files
committed
Polish ProxyHintsTests
1 parent d8003e3 commit 5c2ee24

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Properties;
2222
import java.util.function.Consumer;
2323
import java.util.function.Function;
24-
import java.util.stream.Stream;
2524

2625
import org.junit.jupiter.api.Test;
2726

@@ -32,6 +31,7 @@
3231
* Tests for {@link ProxyHints}.
3332
*
3433
* @author Stephane Nicoll
34+
* @author Sam Brannen
3535
*/
3636
class ProxyHintsTests {
3737

@@ -51,16 +51,15 @@ void registerJdkProxyWithConcreteClass() {
5151
}
5252

5353
@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"));
5958
}
6059

6160
@Test
6261
void registerJdkProxyWithConsumer() {
63-
this.proxyHints.registerJdkProxy(springProxy(TypeReference.of("com.example.Test")));
62+
this.proxyHints.registerJdkProxy(springProxy("com.example.Test"));
6463
assertThat(this.proxyHints.jdkProxies()).singleElement().satisfies(proxiedInterfaces(
6564
"com.example.Test",
6665
"org.springframework.aop.SpringProxy",
@@ -97,28 +96,36 @@ void registerClassProxyWithTargetClass() {
9796

9897
@Test
9998
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());
102102
}
103103

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"));
110111
}
111112

112-
private Consumer<JdkProxyHint> proxiedInterfaces(String... proxiedInterfaces) {
113+
private static Consumer<JdkProxyHint> proxiedInterfaces(String... proxiedInterfaces) {
113114
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
114-
.containsExactly(Arrays.stream(proxiedInterfaces)
115-
.map(TypeReference::of).toArray(TypeReference[]::new));
115+
.containsExactly(toTypeReferences(proxiedInterfaces));
116116
}
117117

118-
private Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
118+
private static Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
119119
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);
122129
}
123130

124131
}

0 commit comments

Comments
 (0)