diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ReflectiveOperationInvoker.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ReflectiveOperationInvoker.java index 16c092fad0..e0547cb815 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ReflectiveOperationInvoker.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ReflectiveOperationInvoker.java @@ -65,8 +65,7 @@ public class ReflectiveOperationInvoker implements OperationInvoker { private void validateRequiredParameters(Map arguments) { Set missingParameters = Stream.of(this.method.getParameters()) - .filter(p -> isMissing(p, arguments)) - .map(Parameter::getName) + .filter((p) -> isMissing(p, arguments)).map(Parameter::getName) .collect(Collectors.toSet()); if (!missingParameters.isEmpty()) { throw new ParametersMissingException(missingParameters); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java index 906d73bb37..c3435408cc 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java @@ -167,7 +167,8 @@ public class EnvironmentEndpoint { private Map> getPropertySourcesAsMap() { Map> map = new LinkedHashMap<>(); for (PropertySource source : getPropertySources()) { - if (!ConfigurationPropertySources.isAttachedConfigurationPropertySource(source)) { + if (!ConfigurationPropertySources + .isAttachedConfigurationPropertySource(source)) { extract("", map, source); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java index 7a5ff317d4..9fcedcf9cf 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java @@ -267,33 +267,39 @@ public class EndpointMBeanTests { } @Test - public void invokeWithParameterMappingExceptionMapsToIllegalArgumentException() throws Exception { + public void invokeWithParameterMappingExceptionMapsToIllegalArgumentException() + throws Exception { load(FooEndpoint.class, (discoverer) -> { ObjectName objectName = registerEndpoint(discoverer, "foo"); try { - this.server.invoke(objectName, "getOne", - new Object[] { "wrong" }, new String[] { String.class.getName() }); + this.server.invoke(objectName, "getOne", new Object[] { "wrong" }, + new String[] { String.class.getName() }); } catch (Exception ex) { - assertThat(ex.getCause()).isExactlyInstanceOf(IllegalArgumentException.class); - assertThat(ex.getCause().getMessage()).isEqualTo(String.format("Failed to map wrong of type " + - "%s to type %s", String.class, FooName.class)); + assertThat(ex.getCause()) + .isExactlyInstanceOf(IllegalArgumentException.class); + assertThat(ex.getCause().getMessage()).isEqualTo( + String.format("Failed to map wrong of type " + "%s to type %s", + String.class, FooName.class)); } }); } @Test - public void invokeWithMissingRequiredParameterExceptionMapsToIllegalArgumentException() throws Exception { + public void invokeWithMissingRequiredParameterExceptionMapsToIllegalArgumentException() + throws Exception { load(RequiredParametersEndpoint.class, (discoverer) -> { ObjectName objectName = registerEndpoint(discoverer, "requiredparameters"); try { - this.server.invoke(objectName, "read", - new Object[] {}, new String[] { String.class.getName() }); + this.server.invoke(objectName, "read", new Object[] {}, + new String[] { String.class.getName() }); } catch (Exception ex) { - assertThat(ex.getCause()).isExactlyInstanceOf(IllegalArgumentException.class); - assertThat(ex.getCause().getMessage()).isEqualTo("Failed to invoke operation because the following " + - "required parameters were missing: foo,baz"); + assertThat(ex.getCause()) + .isExactlyInstanceOf(IllegalArgumentException.class); + assertThat(ex.getCause().getMessage()) + .isEqualTo("Failed to invoke operation because the following " + + "required parameters were missing: foo,baz"); } }); } @@ -304,7 +310,8 @@ public class EndpointMBeanTests { ObjectName objectName = registerEndpoint(discoverer, "requiredparameters"); try { this.server.invoke(objectName, "read", - new Object[] {null, "hello", "world"}, new String[] { String.class.getName() }); + new Object[] { null, "hello", "world" }, + new String[] { String.class.getName() }); } catch (Exception ex) { throw new AssertionError("Nullable parameter should not be required."); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java index 8a17791518..11f058ed00 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java @@ -283,17 +283,16 @@ public abstract class AbstractWebEndpointIntegrationTests client.get().uri("/requiredparameters").exchange() - .expectStatus().isBadRequest()); + public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() + throws Exception { + load(RequiredParameterEndpointConfiguration.class, (client) -> client.get() + .uri("/requiredparameters").exchange().expectStatus().isBadRequest()); } @Test public void readOperationWithMissingNullableParametersIsOk() throws Exception { - load(RequiredParameterEndpointConfiguration.class, - (client) -> client.get().uri("/requiredparameters?foo=hello").exchange() - .expectStatus().isOk()); + load(RequiredParameterEndpointConfiguration.class, (client) -> client.get() + .uri("/requiredparameters?foo=hello").exchange().expectStatus().isOk()); } protected abstract T createApplicationContext(Class... config); diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java index 0d4703600e..82899931fb 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java @@ -40,21 +40,8 @@ import static org.junit.Assert.assertTrue; */ public class JarCommandIT { - private static final boolean java9OrLater; - - static { - boolean loaded = false; - try { - Class.forName("java.security.cert.URICertStoreParameters"); - loaded = true; - } - catch (Exception ex) { - // Continue - } - finally { - java9OrLater = loaded; - } - } + private static final boolean JAVA_9_OR_LATER = isClassPresent( + "java.security.cert.URICertStoreParameters"); private final CommandLineInvoker cli = new CommandLineInvoker( new File("src/it/resources/jar-command")); @@ -83,12 +70,12 @@ public class JarCommandIT { Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(), "bad.groovy"); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertThat(invocation.getErrorOutput(), equalTo("")); } invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy"); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length()); } @@ -99,7 +86,7 @@ public class JarCommandIT { invocation = new Invocation(process); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertThat(invocation.getErrorOutput(), equalTo("")); } } @@ -110,7 +97,7 @@ public class JarCommandIT { Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "jar.groovy"); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length()); } @@ -121,7 +108,7 @@ public class JarCommandIT { invocation = new Invocation(process); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertThat(invocation.getErrorOutput(), equalTo("")); } assertThat(invocation.getStandardOutput(), containsString("Hello World!")); @@ -144,7 +131,7 @@ public class JarCommandIT { Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include", "-public/**,-resources/**", "jar.groovy"); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length()); } @@ -155,7 +142,7 @@ public class JarCommandIT { invocation = new Invocation(process); invocation.await(); - if (!java9OrLater) { + if (!JAVA_9_OR_LATER) { assertThat(invocation.getErrorOutput(), equalTo("")); } assertThat(invocation.getStandardOutput(), containsString("Hello World!")); @@ -168,4 +155,15 @@ public class JarCommandIT { containsString("/templates/template.txt")); assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama")); } + + private static boolean isClassPresent(String name) { + try { + Class.forName(name); + return true; + } + catch (Exception ex) { + return false; + } + } + }