Polish ProxyHintsTests
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -32,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|||||||
* Tests for {@link ProxyHints}.
|
* Tests for {@link ProxyHints}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
class ProxyHintsTests {
|
class ProxyHintsTests {
|
||||||
|
|
||||||
@@ -51,16 +51,15 @@ class ProxyHintsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerJdkProxyWithInterfaceClassNames() {
|
void registerJdkProxyWithTypeReferences() {
|
||||||
this.proxyHints.registerJdkProxy(TypeReference.of(Function.class),
|
this.proxyHints.registerJdkProxy(TypeReference.of(Function.class), TypeReference.of("com.example.Advised"));
|
||||||
TypeReference.of("com.example.Advised"));
|
assertThat(this.proxyHints.jdkProxies()).singleElement()
|
||||||
assertThat(this.proxyHints.jdkProxies()).singleElement().satisfies(proxiedInterfaces(
|
.satisfies(proxiedInterfaces(Function.class.getName(), "com.example.Advised"));
|
||||||
Function.class.getName(), "com.example.Advised"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerJdkProxyWithConsumer() {
|
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(
|
assertThat(this.proxyHints.jdkProxies()).singleElement().satisfies(proxiedInterfaces(
|
||||||
"com.example.Test",
|
"com.example.Test",
|
||||||
"org.springframework.aop.SpringProxy",
|
"org.springframework.aop.SpringProxy",
|
||||||
@@ -97,28 +96,36 @@ class ProxyHintsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerClassProxyWithTargetInterface() {
|
void registerClassProxyWithTargetInterface() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.proxyHints.registerClassProxy(Serializable.class, classProxyHint -> {
|
assertThatIllegalArgumentException()
|
||||||
})).withMessageContaining(Serializable.class.getName());
|
.isThrownBy(() -> this.proxyHints.registerClassProxy(Serializable.class, classProxyHint -> {}))
|
||||||
|
.withMessageContaining(Serializable.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Consumer<JdkProxyHint.Builder> springProxy(TypeReference proxiedInterface) {
|
|
||||||
return builder -> builder
|
private static Consumer<JdkProxyHint.Builder> springProxy(String proxiedInterface) {
|
||||||
.proxiedInterfaces(proxiedInterface)
|
return builder -> builder.proxiedInterfaces(toTypeReferences(
|
||||||
.proxiedInterfaces(Stream.of("org.springframework.aop.SpringProxy",
|
proxiedInterface,
|
||||||
"org.springframework.aop.framework.Advised", "org.springframework.core.DecoratingProxy")
|
"org.springframework.aop.SpringProxy",
|
||||||
.map(TypeReference::of).toArray(TypeReference[]::new));
|
"org.springframework.aop.framework.Advised",
|
||||||
|
"org.springframework.core.DecoratingProxy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<JdkProxyHint> proxiedInterfaces(String... proxiedInterfaces) {
|
private static Consumer<JdkProxyHint> proxiedInterfaces(String... proxiedInterfaces) {
|
||||||
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
|
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
|
||||||
.containsExactly(Arrays.stream(proxiedInterfaces)
|
.containsExactly(toTypeReferences(proxiedInterfaces));
|
||||||
.map(TypeReference::of).toArray(TypeReference[]::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
|
private static Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
|
||||||
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
|
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
|
||||||
.containsExactly(Arrays.stream(proxiedInterfaces)
|
.containsExactly(toTypeReferences(proxiedInterfaces));
|
||||||
.map(TypeReference::of).toArray(TypeReference[]::new));
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user