Merge pull request #13320 from izeye:polish-20180601

* pr/13320:
  Polish
pull/13388/head
Stephane Nicoll 7 years ago
commit 152ce145fd

@ -223,7 +223,7 @@ This module contains core items and annotations that can be helpful when testing
=== spring-boot-test-autoconfigure === spring-boot-test-autoconfigure
Like other Spring Boot Auto-Configuration modules, spring-boot-test-autoconfigure, provides auto-configuration Like other Spring Boot auto-configuration modules, spring-boot-test-autoconfigure, provides auto-configuration
for tests based on the classpath. It includes a number of annotations that can be used to automatically for tests based on the classpath. It includes a number of annotations that can be used to automatically
configure a slice of your application that needs to be tested. configure a slice of your application that needs to be tested.

@ -39,7 +39,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* {@link EnableAutoConfiguration Auto-Configuration} for Jest. * {@link EnableAutoConfiguration Auto-configuration} for Jest.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.4.0 * @since 1.4.0

@ -134,7 +134,9 @@ public class Restarter {
Assert.notNull(thread, "Thread must not be null"); Assert.notNull(thread, "Thread must not be null");
Assert.notNull(args, "Args must not be null"); Assert.notNull(args, "Args must not be null");
Assert.notNull(initializer, "Initializer must not be null"); Assert.notNull(initializer, "Initializer must not be null");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Creating new Restarter for thread " + thread); this.logger.debug("Creating new Restarter for thread " + thread);
}
SilentExitExceptionHandler.setup(thread); SilentExitExceptionHandler.setup(thread);
this.forceReferenceCleanup = forceReferenceCleanup; this.forceReferenceCleanup = forceReferenceCleanup;
this.initialUrls = initializer.getInitialUrls(thread); this.initialUrls = initializer.getInitialUrls(thread);
@ -360,7 +362,10 @@ public class Restarter {
clear(Class.forName(className), fieldName); clear(Class.forName(className), fieldName);
} }
catch (Exception ex) { catch (Exception ex) {
this.logger.debug("Unable to clear field " + className + " " + fieldName, ex); if (this.logger.isDebugEnabled()) {
this.logger.debug("Unable to clear field " + className + " " + fieldName,
ex);
}
} }
} }
@ -377,15 +382,15 @@ public class Restarter {
} }
} }
catch (Exception ex) { catch (Exception ex) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Unable to clear field " + type + " " + fieldName, ex); this.logger.debug("Unable to clear field " + type + " " + fieldName, ex);
} }
} }
}
private boolean isFromRestartClassLoader(Object object) { private boolean isFromRestartClassLoader(Object object) {
if (object instanceof Class) { return (object instanceof Class
return ((Class<?>) object).getClassLoader() instanceof RestartClassLoader; && ((Class<?>) object).getClassLoader() instanceof RestartClassLoader);
}
return false;
} }
/** /**

@ -662,7 +662,7 @@ that you have added. Since `spring-boot-starter-web` added Tomcat and Spring MVC
auto-configuration assumes that you are developing a web application and sets up Spring auto-configuration assumes that you are developing a web application and sets up Spring
accordingly. accordingly.
.Starters and Auto-Configuration .Starters and Auto-configuration
**** ****
Auto-configuration is designed to work well with "`Starters`", but the two concepts are Auto-configuration is designed to work well with "`Starters`", but the two concepts are
not directly tied. You are free to pick and choose jar dependencies outside of the not directly tied. You are free to pick and choose jar dependencies outside of the

@ -2064,7 +2064,7 @@ directory locations). The root Servlet context path, `"/"`, is automatically add
location as well. location as well.
In addition to the "`standard`" static resource locations mentioned earlier, a special In addition to the "`standard`" static resource locations mentioned earlier, a special
case is made for http://www.webjars.org/[Webjars content]. Any resources with a path in case is made for https://www.webjars.org/[Webjars content]. Any resources with a path in
`+/webjars/**+` are served from jar files if they are packaged in the Webjars format. `+/webjars/**+` are served from jar files if they are packaged in the Webjars format.
TIP: Do not use the `src/main/webapp` directory if your application is packaged as a jar. TIP: Do not use the `src/main/webapp` directory if your application is packaged as a jar.
@ -2625,7 +2625,7 @@ custom locations. So, if there is an `index.html` in any of your locations on st
is the home page of the application. is the home page of the application.
In addition to the "`standard`" static resource locations listed earlier, a special case In addition to the "`standard`" static resource locations listed earlier, a special case
is made for http://www.webjars.org/[Webjars content]. Any resources with a path in is made for https://www.webjars.org/[Webjars content]. Any resources with a path in
`+/webjars/**+` are served from jar files if they are packaged in the Webjars format. `+/webjars/**+` are served from jar files if they are packaged in the Webjars format.
TIP: Spring WebFlux applications do not strictly depend on the Servlet API, so they TIP: Spring WebFlux applications do not strictly depend on the Servlet API, so they
@ -7227,7 +7227,7 @@ which auto-configures one for you.
[[boot-features-environment-test-utilities]] [[boot-features-test-property-values]]
==== TestPropertyValues ==== TestPropertyValues
`TestPropertyValues` lets you quickly add properties to a `TestPropertyValues` lets you quickly add properties to a
`ConfigurableEnvironment` or `ConfigurableApplicationContext`. You can call it with `ConfigurableEnvironment` or `ConfigurableApplicationContext`. You can call it with

@ -99,11 +99,11 @@ final class StringSequence implements CharSequence {
return startsWith(prefix, 0); return startsWith(prefix, 0);
} }
public boolean startsWith(CharSequence prefix, int toffset) { public boolean startsWith(CharSequence prefix, int offset) {
if (length() - prefix.length() - toffset < 0) { if (length() - prefix.length() - offset < 0) {
return false; return false;
} }
return subSequence(toffset, toffset + prefix.length()).equals(prefix); return subSequence(offset, offset + prefix.length()).equals(prefix);
} }
@Override @Override

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -301,7 +302,7 @@ public class ConfigFileApplicationListener
private final List<PropertySourceLoader> propertySourceLoaders; private final List<PropertySourceLoader> propertySourceLoaders;
private LinkedList<Profile> profiles; private Deque<Profile> profiles;
private List<Profile> processedProfiles; private List<Profile> processedProfiles;
@ -345,9 +346,9 @@ public class ConfigFileApplicationListener
// The default profile for these purposes is represented as null. We add it // The default profile for these purposes is represented as null. We add it
// first so that it is processed first and has lowest priority. // first so that it is processed first and has lowest priority.
this.profiles.add(null); this.profiles.add(null);
Set<Profile> activatedViaProperty = getProfilesActivatedViaActiveProfileProperty(); Set<Profile> activatedViaProperty = getProfilesActivatedViaProperty();
processOtherActiveProfiles(activatedViaProperty); processOtherActiveProfiles(activatedViaProperty);
// Any pre-existing active activeProfiles set via property sources (e.g. // Any pre-existing active profiles set via property sources (e.g.
// System // System
// properties) take precedence over those added in config files. // properties) take precedence over those added in config files.
addActiveProfiles(activatedViaProperty); addActiveProfiles(activatedViaProperty);
@ -360,7 +361,7 @@ public class ConfigFileApplicationListener
} }
} }
private Set<Profile> getProfilesActivatedViaActiveProfileProperty() { private Set<Profile> getProfilesActivatedViaProperty() {
if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY) if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)
&& !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) { && !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) {
return Collections.emptySet(); return Collections.emptySet();
@ -385,8 +386,10 @@ public class ConfigFileApplicationListener
return; return;
} }
addProfiles(profiles); addProfiles(profiles);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Activated activeProfiles " this.logger.debug("Activated activeProfiles "
+ StringUtils.collectionToCommaDelimitedString(profiles)); + StringUtils.collectionToCommaDelimitedString(profiles));
}
this.activatedProfiles = true; this.activatedProfiles = true;
removeUnprocessedDefaultProfiles(); removeUnprocessedDefaultProfiles();
} }

@ -58,62 +58,49 @@ public class SampleTomcatDeployApplicationIT {
@Test @Test
public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse() public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse()
throws Exception { throws Exception {
assertThatErrorFromExceptionProducesExpectedResponse(MediaType.ALL, assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL,
MediaType.APPLICATION_JSON); MediaType.APPLICATION_JSON);
} }
@Test @Test
public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse() public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse()
throws Exception { throws Exception {
assertThatErrorFromExceptionProducesExpectedResponse(MediaType.APPLICATION_JSON, assertThatPathProducesExpectedResponse("/bootapp/exception",
MediaType.APPLICATION_JSON); MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
} }
@Test @Test
public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse() public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse()
throws Exception { throws Exception {
assertThatErrorFromExceptionProducesExpectedResponse(MediaType.TEXT_HTML, assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML,
MediaType.TEXT_HTML); MediaType.TEXT_HTML);
} }
@Test @Test
public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse() public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse()
throws Exception { throws Exception {
assertThatSendErrorProducesExpectedResponse(MediaType.ALL, assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL,
MediaType.APPLICATION_JSON); MediaType.APPLICATION_JSON);
} }
@Test @Test
public void sendErrorForRequestAcceptingJsonProducesAJsonResponse() throws Exception { public void sendErrorForRequestAcceptingJsonProducesAJsonResponse() throws Exception {
assertThatSendErrorProducesExpectedResponse(MediaType.APPLICATION_JSON, assertThatPathProducesExpectedResponse("/bootapp/send-error",
MediaType.APPLICATION_JSON); MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
} }
@Test @Test
public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse() public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse()
throws Exception { throws Exception {
assertThatSendErrorProducesExpectedResponse(MediaType.TEXT_HTML, assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML,
MediaType.TEXT_HTML); MediaType.TEXT_HTML);
} }
private void assertThatSendErrorProducesExpectedResponse(MediaType accept, private void assertThatPathProducesExpectedResponse(String path, MediaType accept,
MediaType contentType) {
RequestEntity<Void> request = RequestEntity
.get(URI.create("http://localhost:" + this.port + "/bootapp/send-error"))
.accept(accept).build();
ResponseEntity<String> response = this.rest.exchange(request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType()))
.as("%s is compatible with %s", contentType,
response.getHeaders().getContentType())
.isTrue();
}
private void assertThatErrorFromExceptionProducesExpectedResponse(MediaType accept,
MediaType contentType) { MediaType contentType) {
RequestEntity<Void> request = RequestEntity RequestEntity<Void> request = RequestEntity
.get(URI.create("http://localhost:" + this.port + "/bootapp/exception")) .get(URI.create("http://localhost:" + this.port + path)).accept(accept)
.accept(accept).build(); .build();
ResponseEntity<String> response = this.rest.exchange(request, String.class); ResponseEntity<String> response = this.rest.exchange(request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType())) assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType()))

Loading…
Cancel
Save