From f46d799f31667c509dbbbc0522f5370d1f006345 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 17 Apr 2017 22:08:51 -0700 Subject: [PATCH] Polish --- ...althMvcEndpointAutoConfigurationTests.java | 8 +++-- .../json/ExampleJsonObjectWithView.java | 1 - .../json/JsonTestIntegrationTests.java | 5 ++-- .../test/json/AbstractJsonMarshalTester.java | 4 +++ .../boot/test/json/JacksonTester.java | 7 +++-- .../boot/test/json/ExampleObject.java | 1 - .../json/JacksonTesterIntegrationTests.java | 29 +++++++++++-------- .../admin/SpringApplicationAdminMXBean.java | 6 ++-- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java index 1bf606ee95..5cd92ac134 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java @@ -108,7 +108,8 @@ public class HealthMvcEndpointAutoConfigurationTests { public void endpointConditionalOnMissingBean() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); - this.context.register(TestConfiguration.class, TestHealthMvcEndpointConfiguration.class); + this.context.register(TestConfiguration.class, + TestHealthMvcEndpointConfiguration.class); this.context.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(); Health health = (Health) this.context.getBean(HealthMvcEndpoint.class) @@ -142,6 +143,7 @@ public class HealthMvcEndpointAutoConfigurationTests { public HealthMvcEndpoint endpoint(HealthEndpoint endpoint) { return new TestHealthMvcEndpoint(endpoint); } + } static class TestHealthMvcEndpoint extends HealthMvcEndpoint { @@ -151,9 +153,11 @@ public class HealthMvcEndpointAutoConfigurationTests { } @Override - protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) { + protected boolean exposeHealthDetails(HttpServletRequest request, + Principal principal) { return true; } + } static class TestHealthIndicator extends AbstractHealthIndicator { diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonObjectWithView.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonObjectWithView.java index 7bc564494d..25ae8ea9a3 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonObjectWithView.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonObjectWithView.java @@ -73,4 +73,3 @@ public class ExampleJsonObjectWithView { } } - diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java index 0448e6c392..35aeb19aa0 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java @@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Integration tests for {@link JsonTest}. * * @author Phillip Webb + * @author Madhura Bhave */ @RunWith(SpringRunner.class) @JsonTest @@ -82,9 +83,9 @@ public class JsonTestIntegrationTests { ExampleJsonObjectWithView object = new ExampleJsonObjectWithView(); object.setValue("spring"); JsonContent content = this.jacksonWithViewJson - .forView(ExampleJsonObjectWithView.TestView.class) - .write(object); + .forView(ExampleJsonObjectWithView.TestView.class).write(object); assertThat(content).doesNotHaveJsonPathValue("id"); assertThat(content).isEqualToJson("example.json"); } + } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java b/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java index fbf56fa63c..4df775eb61 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java @@ -113,6 +113,10 @@ public abstract class AbstractJsonMarshalTester { return this.type; } + /** + * Return class used to load relative resources. + * @return the resource load class + */ protected final Class getResourceLoadClass() { return this.resourceLoadClass; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java b/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java index d72d9d8138..65ba7f22fa 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java @@ -152,13 +152,14 @@ public class JacksonTester extends AbstractJsonMarshalTester { } /** - * Returns a new instance of {@link JacksonTester} with the view - * that should be used for json serialization/deserialization. + * Returns a new instance of {@link JacksonTester} with the view that should be used + * for json serialization/deserialization. * @param view the view class * @return the new instance */ public JacksonTester forView(Class view) { - return new JacksonTester(this.getResourceLoadClass(), this.getType(), this.objectMapper, view); + return new JacksonTester(this.getResourceLoadClass(), this.getType(), + this.objectMapper, view); } /** diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java b/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java index 5c8d45e18b..9ad5a00d49 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java @@ -64,4 +64,3 @@ public class ExampleObject { } } - diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java index 74c693c2bc..1d6ae97a1b 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java @@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Integration tests for {@link JacksonTester}. Shows typical usage. * * @author Phillip Webb + * @author Madhura Bhave */ public class JacksonTesterIntegrationTests { @@ -56,6 +57,13 @@ public class JacksonTesterIntegrationTests { JacksonTester.initFields(this, this.objectMapper); } + @Test + public void typicalTest() throws Exception { + String example = JSON; + assertThat(this.simpleJson.parse(example).getObject().getName()) + .isEqualTo("Spring"); + } + @Test public void typicalListTest() throws Exception { String example = "[" + JSON + "]"; @@ -79,10 +87,9 @@ public class JacksonTesterIntegrationTests { ExampleObjectWithView object = new ExampleObjectWithView(); object.setName("Spring"); object.setAge(123); - JsonContent content = this.jsonWithView.forView( - ExampleObjectWithView.TestView.class).write(object); - assertThat(content).extractingJsonPathStringValue("@.name") - .isEqualTo("Spring"); + JsonContent content = this.jsonWithView + .forView(ExampleObjectWithView.TestView.class).write(object); + assertThat(content).extractingJsonPathStringValue("@.name").isEqualTo("Spring"); assertThat(content).doesNotHaveJsonPathValue("age"); } @@ -90,10 +97,9 @@ public class JacksonTesterIntegrationTests { public void readWithResourceAndView() throws Exception { this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION); ByteArrayResource resource = new ByteArrayResource(JSON.getBytes()); - ObjectContent content = this.jsonWithView.forView( - ExampleObjectWithView.TestView.class).read(resource); - assertThat(content.getObject().getName()) - .isEqualTo("Spring"); + ObjectContent content = this.jsonWithView + .forView(ExampleObjectWithView.TestView.class).read(resource); + assertThat(content.getObject().getName()).isEqualTo("Spring"); assertThat(content.getObject().getAge()).isEqualTo(0); } @@ -101,10 +107,9 @@ public class JacksonTesterIntegrationTests { public void readWithReaderAndView() throws Exception { this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION); Reader reader = new StringReader(JSON); - ObjectContent content = this.jsonWithView.forView( - ExampleObjectWithView.TestView.class).read(reader); - assertThat(content.getObject().getName()) - .isEqualTo("Spring"); + ObjectContent content = this.jsonWithView + .forView(ExampleObjectWithView.TestView.class).read(reader); + assertThat(content.getObject().getName()).isEqualTo("Spring"); assertThat(content.getObject().getAge()).isEqualTo(0); } diff --git a/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java b/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java index 992c27d7ef..7fc93489d0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java @@ -33,9 +33,9 @@ public interface SpringApplicationAdminMXBean { boolean isReady(); /** - * Specify if the application runs in an embedded web container. Return - * {@code false} on a web application that hasn't fully started yet, so it is - * preferable to wait for the application to be {@link #isReady() ready}. + * Specify if the application runs in an embedded web container. Return {@code false} + * on a web application that hasn't fully started yet, so it is preferable to wait for + * the application to be {@link #isReady() ready}. * @return {@code true} if the application runs in an embedded web container * @see #isReady() */