From 5c2ee249b5d14bb87f8dd8d11cbed6fc87dae1b9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 11 Jul 2022 17:23:34 +0200 Subject: [PATCH] Polish ProxyHintsTests --- .../aot/hint/ProxyHintsTests.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java index ff749c91502..ffafa942e00 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.Properties; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -32,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * Tests for {@link ProxyHints}. * * @author Stephane Nicoll + * @author Sam Brannen */ class ProxyHintsTests { @@ -51,16 +51,15 @@ class ProxyHintsTests { } @Test - void registerJdkProxyWithInterfaceClassNames() { - this.proxyHints.registerJdkProxy(TypeReference.of(Function.class), - TypeReference.of("com.example.Advised")); - assertThat(this.proxyHints.jdkProxies()).singleElement().satisfies(proxiedInterfaces( - Function.class.getName(), "com.example.Advised")); + void registerJdkProxyWithTypeReferences() { + this.proxyHints.registerJdkProxy(TypeReference.of(Function.class), TypeReference.of("com.example.Advised")); + assertThat(this.proxyHints.jdkProxies()).singleElement() + .satisfies(proxiedInterfaces(Function.class.getName(), "com.example.Advised")); } @Test void registerJdkProxyWithConsumer() { - this.proxyHints.registerJdkProxy(springProxy(TypeReference.of("com.example.Test"))); + this.proxyHints.registerJdkProxy(springProxy("com.example.Test")); assertThat(this.proxyHints.jdkProxies()).singleElement().satisfies(proxiedInterfaces( "com.example.Test", "org.springframework.aop.SpringProxy", @@ -97,28 +96,36 @@ class ProxyHintsTests { @Test void registerClassProxyWithTargetInterface() { - assertThatIllegalArgumentException().isThrownBy(() -> this.proxyHints.registerClassProxy(Serializable.class, classProxyHint -> { - })).withMessageContaining(Serializable.class.getName()); + assertThatIllegalArgumentException() + .isThrownBy(() -> this.proxyHints.registerClassProxy(Serializable.class, classProxyHint -> {})) + .withMessageContaining(Serializable.class.getName()); } - private static Consumer springProxy(TypeReference proxiedInterface) { - return builder -> builder - .proxiedInterfaces(proxiedInterface) - .proxiedInterfaces(Stream.of("org.springframework.aop.SpringProxy", - "org.springframework.aop.framework.Advised", "org.springframework.core.DecoratingProxy") - .map(TypeReference::of).toArray(TypeReference[]::new)); + + private static Consumer springProxy(String proxiedInterface) { + return builder -> builder.proxiedInterfaces(toTypeReferences( + proxiedInterface, + "org.springframework.aop.SpringProxy", + "org.springframework.aop.framework.Advised", + "org.springframework.core.DecoratingProxy")); } - private Consumer proxiedInterfaces(String... proxiedInterfaces) { + private static Consumer proxiedInterfaces(String... proxiedInterfaces) { return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces()) - .containsExactly(Arrays.stream(proxiedInterfaces) - .map(TypeReference::of).toArray(TypeReference[]::new)); + .containsExactly(toTypeReferences(proxiedInterfaces)); } - private Consumer proxiedInterfaces(Class... proxiedInterfaces) { + private static Consumer proxiedInterfaces(Class... proxiedInterfaces) { return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces()) - .containsExactly(Arrays.stream(proxiedInterfaces) - .map(TypeReference::of).toArray(TypeReference[]::new)); + .containsExactly(toTypeReferences(proxiedInterfaces)); + } + + private static TypeReference[] toTypeReferences(String... proxiedInterfaces) { + return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new); + } + + private static TypeReference[] toTypeReferences(Class... proxiedInterfaces) { + return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new); } }