From 620208a80243aa2e38961b9e86eb8c3f20fa10c6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 16 Mar 2018 13:24:39 -0700 Subject: [PATCH] Polish --- .../autoconfigure/web/ErrorProperties.java | 4 +- .../DefaultErrorWebExceptionHandler.java | 8 ++-- .../CouchbaseAutoConfigurationTests.java | 2 +- ...orWebExceptionHandlerIntegrationTests.java | 42 +++++++------------ ...ringConfigurationPropertySourcesTests.java | 2 +- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java index f210e54563..c7553e3703 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java @@ -103,7 +103,8 @@ public class ErrorProperties { public static class Whitelabel { /** - * Whether to enable the default error page displayed in browsers in case of a server error. + * Whether to enable the default error page displayed in browsers in case of a + * server error. */ private boolean enabled = true; @@ -114,6 +115,7 @@ public class ErrorProperties { public void setEnabled(boolean enabled) { this.enabled = enabled; } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java index ca9adece16..12ee94a5bc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java @@ -119,20 +119,20 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa boolean includeStackTrace = isIncludeStackTrace(request, MediaType.TEXT_HTML); Map error = getErrorAttributes(request, includeStackTrace); HttpStatus errorStatus = getHttpStatus(error); - ServerResponse.BodyBuilder response = ServerResponse.status(errorStatus) + ServerResponse.BodyBuilder responseBody = ServerResponse.status(errorStatus) .contentType(MediaType.TEXT_HTML); Flux result = Flux .just("error/" + errorStatus.toString(), "error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error") - .flatMap((viewName) -> renderErrorView(viewName, response, error)); + .flatMap((viewName) -> renderErrorView(viewName, responseBody, error)); if (this.errorProperties.getWhitelabel().isEnabled()) { - result = result.switchIfEmpty(renderDefaultErrorView(response, error)); + result = result.switchIfEmpty(renderDefaultErrorView(responseBody, error)); } else { Throwable ex = getError(request); result = result.switchIfEmpty(Mono.error(ex)); } - return result.next().doOnNext((resp) -> logError(request, errorStatus)); + return result.next().doOnNext((response) -> logError(request, errorStatus)); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java index c69b4a09a0..eb30f3ff8a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java @@ -53,7 +53,7 @@ public class CouchbaseAutoConfigurationTests { @Test public void bootstrapHostsIsRequired() { - this.contextRunner.run((context) -> assertNoCouchbaseBeans(context)); + this.contextRunner.run(this::assertNoCouchbaseBeans); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java index 0400ce76ae..41e00cd414 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java @@ -95,10 +95,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { this.contextRunner.run((context) -> { WebTestClient client = WebTestClient.bindToApplicationContext(context) .build(); - client.get().uri("/notFound").exchange() - .expectStatus().isNotFound() - .expectBody().jsonPath("status") - .isEqualTo("404").jsonPath("error") + client.get().uri("/notFound").exchange().expectStatus().isNotFound() + .expectBody().jsonPath("status").isEqualTo("404").jsonPath("error") .isEqualTo(HttpStatus.NOT_FOUND.getReasonPhrase()).jsonPath("path") .isEqualTo(("/notFound")).jsonPath("exception").doesNotExist(); }); @@ -125,10 +123,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { WebTestClient client = WebTestClient.bindToApplicationContext(context) .build(); client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON) - .syncBody("{}").exchange() - .expectStatus().isBadRequest() - .expectBody().jsonPath("status") - .isEqualTo("400").jsonPath("error") + .syncBody("{}").exchange().expectStatus().isBadRequest().expectBody() + .jsonPath("status").isEqualTo("400").jsonPath("error") .isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path") .isEqualTo(("/bind")).jsonPath("exception").doesNotExist() .jsonPath("errors").isArray().jsonPath("message").isNotEmpty(); @@ -195,10 +191,9 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { .run((context) -> { WebTestClient client = WebTestClient.bindToApplicationContext(context) .build(); - client.get().uri("/badRequest").exchange() - .expectStatus().isBadRequest() - .expectBody().jsonPath("status").isEqualTo("400") - .jsonPath("error") + client.get().uri("/badRequest").exchange().expectStatus() + .isBadRequest().expectBody().jsonPath("status") + .isEqualTo("400").jsonPath("error") .isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()) .jsonPath("exception") .isEqualTo(ResponseStatusException.class.getName()); @@ -254,9 +249,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { WebTestClient client = WebTestClient.bindToApplicationContext(context) .build(); String body = client.get().uri("/notfound") - .accept(MediaType.TEXT_HTML).exchange() - .expectStatus().isNotFound() - .expectHeader().contentType(MediaType.TEXT_HTML) + .accept(MediaType.TEXT_HTML).exchange().expectStatus() + .isNotFound().expectHeader().contentType(MediaType.TEXT_HTML) .expectBody(String.class).returnResult().getResponseBody(); assertThat(body).contains("Whitelabel Error Page") .contains("type=Not Found, status=404"); @@ -276,17 +270,13 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { @Test public void whilelabelDisabled() { - this.contextRunner - .withPropertyValues("server.error.whitelabel.enabled=false", - "spring.mustache.prefix=classpath:/unknown/") - .run((context) -> { - WebTestClient client = WebTestClient.bindToApplicationContext(context) - .build(); - client.get().uri("/notfound") - .accept(MediaType.TEXT_HTML).exchange() - .expectStatus().isNotFound() - .expectBody().isEmpty(); - }); + this.contextRunner.withPropertyValues("server.error.whitelabel.enabled=false", + "spring.mustache.prefix=classpath:/unknown/").run((context) -> { + WebTestClient client = WebTestClient.bindToApplicationContext(context) + .build(); + client.get().uri("/notfound").accept(MediaType.TEXT_HTML).exchange() + .expectStatus().isNotFound().expectBody().isEmpty(); + }); } @Configuration diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySourcesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySourcesTests.java index c187c815b9..bb550c0560 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySourcesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySourcesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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.