diff --git a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerTests.java b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerTests.java index 91981540b7..8a2c697b69 100644 --- a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerTests.java +++ b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.remoting.RemoteAccessException; import org.springframework.remoting.support.DefaultRemoteInvocationExecutor; import org.springframework.remoting.support.RemoteInvocation; -import org.springframework.remoting.support.RemoteInvocationFactory; import org.springframework.remoting.support.RemoteInvocationResult; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -55,19 +54,20 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Juergen Hoeller * @since 09.08.2004 */ -public class HttpInvokerTests { +@SuppressWarnings("deprecation") +class HttpInvokerTests { @Test - public void httpInvokerProxyFactoryBeanAndServiceExporter() throws Throwable { + void httpInvokerProxyFactoryBeanAndServiceExporter() { doTestHttpInvokerProxyFactoryBeanAndServiceExporter(false); } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithExplicitClassLoader() throws Throwable { + void httpInvokerProxyFactoryBeanAndServiceExporterWithExplicitClassLoader() { doTestHttpInvokerProxyFactoryBeanAndServiceExporter(true); } - private void doTestHttpInvokerProxyFactoryBeanAndServiceExporter(boolean explicitClassLoader) throws Throwable { + private void doTestHttpInvokerProxyFactoryBeanAndServiceExporter(boolean explicitClassLoader) { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); @@ -124,7 +124,7 @@ public class HttpInvokerTests { } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception { + void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); @@ -136,23 +136,17 @@ public class HttpInvokerTests { pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl("https://myurl"); - pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { - @Override - public RemoteInvocationResult executeRequest( - HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { - throw new IOException("argh"); - } - }); + pfb.setHttpInvokerRequestExecutor((config, invocation) -> { throw new IOException("argh"); }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); - assertThatExceptionOfType(RemoteAccessException.class).isThrownBy(() -> - proxy.setAge(50)) + assertThatExceptionOfType(RemoteAccessException.class) + .isThrownBy(() -> proxy.setAge(50)) .withCauseInstanceOf(IOException.class); } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithGzipCompression() throws Throwable { + void httpInvokerProxyFactoryBeanAndServiceExporterWithGzipCompression() { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter() { @@ -227,7 +221,7 @@ public class HttpInvokerTests { } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithWrappedInvocations() throws Throwable { + void httpInvokerProxyFactoryBeanAndServiceExporterWithWrappedInvocations() { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter() { @@ -297,7 +291,7 @@ public class HttpInvokerTests { } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithInvocationAttributes() throws Exception { + void httpInvokerProxyFactoryBeanAndServiceExporterWithInvocationAttributes() { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); @@ -319,9 +313,7 @@ public class HttpInvokerTests { HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl("https://myurl"); - pfb.setRemoteInvocationFactory(new RemoteInvocationFactory() { - @Override - public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { + pfb.setRemoteInvocationFactory(methodInvocation -> { RemoteInvocation invocation = new RemoteInvocation(methodInvocation); invocation.addAttribute("myKey", "myValue"); assertThatIllegalStateException().isThrownBy(() -> @@ -331,7 +323,6 @@ public class HttpInvokerTests { assertThat(invocation.getAttributes().get("myKey")).isEqualTo("myValue"); assertThat(invocation.getAttribute("myKey")).isEqualTo("myValue"); return invocation; - } }); pfb.setHttpInvokerRequestExecutor(new AbstractHttpInvokerRequestExecutor() { @@ -355,7 +346,7 @@ public class HttpInvokerTests { } @Test - public void httpInvokerProxyFactoryBeanAndServiceExporterWithCustomInvocationObject() throws Exception { + void httpInvokerProxyFactoryBeanAndServiceExporterWithCustomInvocationObject() { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); @@ -377,14 +368,11 @@ public class HttpInvokerTests { HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl("https://myurl"); - pfb.setRemoteInvocationFactory(new RemoteInvocationFactory() { - @Override - public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { + pfb.setRemoteInvocationFactory(methodInvocation -> { RemoteInvocation invocation = new TestRemoteInvocation(methodInvocation); assertThat(invocation.getAttributes()).isNull(); assertThat(invocation.getAttribute("myKey")).isNull(); return invocation; - } }); pfb.setHttpInvokerRequestExecutor(new AbstractHttpInvokerRequestExecutor() { @@ -408,19 +396,13 @@ public class HttpInvokerTests { } @Test - public void httpInvokerWithSpecialLocalMethods() throws Exception { + void httpInvokerWithSpecialLocalMethods() { String serviceUrl = "https://myurl"; HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl(serviceUrl); - pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { - @Override - public RemoteInvocationResult executeRequest( - HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { - throw new IOException("argh"); - } - }); + pfb.setHttpInvokerRequestExecutor((config, invocation) -> { throw new IOException("argh"); }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); @@ -432,9 +414,8 @@ public class HttpInvokerTests { assertThat(proxy.equals(proxy)).isTrue(); // should go through - - assertThatExceptionOfType(RemoteAccessException.class).isThrownBy(() -> - proxy.setAge(50)) + assertThatExceptionOfType(RemoteAccessException.class) + .isThrownBy(() -> proxy.setAge(50)) .withCauseInstanceOf(IOException.class); } @@ -442,7 +423,7 @@ public class HttpInvokerTests { @SuppressWarnings("serial") private static class TestRemoteInvocation extends RemoteInvocation { - public TestRemoteInvocation(MethodInvocation methodInvocation) { + TestRemoteInvocation(MethodInvocation methodInvocation) { super(methodInvocation); } } @@ -453,7 +434,7 @@ public class HttpInvokerTests { private final RemoteInvocation remoteInvocation; - public TestRemoteInvocationWrapper(RemoteInvocation remoteInvocation) { + TestRemoteInvocationWrapper(RemoteInvocation remoteInvocation) { this.remoteInvocation = remoteInvocation; } } @@ -464,7 +445,7 @@ public class HttpInvokerTests { private final RemoteInvocationResult remoteInvocationResult; - public TestRemoteInvocationResultWrapper(RemoteInvocationResult remoteInvocationResult) { + TestRemoteInvocationResultWrapper(RemoteInvocationResult remoteInvocationResult) { this.remoteInvocationResult = remoteInvocationResult; } }