Merge pull request #11372 from izeye:polish-20171218

* pr/11372:
  Polish
pull/11364/merge
Stephane Nicoll 7 years ago
commit 1867ba6362

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.http.CacheControl;
/** /**
* Properties used to configure resource handling. * Properties used to configure resource handling.
@ -458,9 +459,9 @@ public class ResourceProperties {
this.sMaxAge = sMaxAge; this.sMaxAge = sMaxAge;
} }
public org.springframework.http.CacheControl toHttpCacheControl() { public CacheControl toHttpCacheControl() {
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get();
org.springframework.http.CacheControl control = createCacheControl(); CacheControl control = createCacheControl();
map.from(this::getMustRevalidate).whenTrue() map.from(this::getMustRevalidate).whenTrue()
.toCall(control::mustRevalidate); .toCall(control::mustRevalidate);
map.from(this::getNoTransform).whenTrue().toCall(control::noTransform); map.from(this::getNoTransform).whenTrue().toCall(control::noTransform);
@ -478,18 +479,18 @@ public class ResourceProperties {
return control; return control;
} }
private org.springframework.http.CacheControl createCacheControl() { private CacheControl createCacheControl() {
if (Boolean.TRUE.equals(this.noStore)) { if (Boolean.TRUE.equals(this.noStore)) {
return org.springframework.http.CacheControl.noStore(); return CacheControl.noStore();
} }
if (Boolean.TRUE.equals(this.noCache)) { if (Boolean.TRUE.equals(this.noCache)) {
return org.springframework.http.CacheControl.noCache(); return CacheControl.noCache();
} }
if (this.maxAge != null) { if (this.maxAge != null) {
return org.springframework.http.CacheControl return CacheControl
.maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS); .maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS);
} }
return org.springframework.http.CacheControl.empty(); return CacheControl.empty();
} }
} }

@ -22,7 +22,6 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.TimeZone;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonCreator.Mode; import com.fasterxml.jackson.annotation.JsonCreator.Mode;
@ -457,7 +456,7 @@ public class JacksonAutoConfigurationTests {
ObjectMapper mapper = this.context.getBean(ObjectMapper.class); ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC); DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
String expected = FormatConfig.DEFAULT_DATETIME_PRINTER.rawFormatter() String expected = FormatConfig.DEFAULT_DATETIME_PRINTER.rawFormatter()
.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))) .withZone(DateTimeZone.UTC)
.print(dateTime); .print(dateTime);
assertThat(mapper.writeValueAsString(dateTime)).isEqualTo("\"" + expected + "\""); assertThat(mapper.writeValueAsString(dateTime)).isEqualTo("\"" + expected + "\"");
} }

@ -22,6 +22,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache; import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache;
import org.springframework.boot.testsupport.assertj.Matched; import org.springframework.boot.testsupport.assertj.Matched;
import org.springframework.http.CacheControl;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.endsWith;
@ -73,7 +74,7 @@ public class ResourcePropertiesTests {
@Test @Test
public void emptyCacheControl() { public void emptyCacheControl() {
org.springframework.http.CacheControl cacheControl = this.properties.getCache() CacheControl cacheControl = this.properties.getCache()
.getCachecontrol().toHttpCacheControl(); .getCachecontrol().toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isNull(); assertThat(cacheControl.getHeaderValue()).isNull();
} }
@ -90,8 +91,7 @@ public class ResourcePropertiesTests {
properties.setSMaxAge(Duration.ofSeconds(5)); properties.setSMaxAge(Duration.ofSeconds(5));
properties.setStaleIfError(Duration.ofSeconds(6)); properties.setStaleIfError(Duration.ofSeconds(6));
properties.setStaleWhileRevalidate(Duration.ofSeconds(7)); properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
org.springframework.http.CacheControl cacheControl = properties CacheControl cacheControl = properties.toHttpCacheControl();
.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isEqualTo( assertThat(cacheControl.getHeaderValue()).isEqualTo(
"max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate," "max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
+ " s-maxage=5, stale-if-error=6, stale-while-revalidate=7"); + " s-maxage=5, stale-if-error=6, stale-while-revalidate=7");
@ -102,8 +102,7 @@ public class ResourcePropertiesTests {
Cache.Cachecontrol properties = this.properties.getCache().getCachecontrol(); Cache.Cachecontrol properties = this.properties.getCache().getCachecontrol();
properties.setMaxAge(Duration.ofSeconds(4)); properties.setMaxAge(Duration.ofSeconds(4));
properties.setNoStore(true); properties.setNoStore(true);
org.springframework.http.CacheControl cacheControl = properties CacheControl cacheControl = properties.toHttpCacheControl();
.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store"); assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
} }

@ -46,10 +46,14 @@ public class FilteredClassLoaderTests {
public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception { public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception {
FilteredClassLoader classLoader = new FilteredClassLoader( FilteredClassLoader classLoader = new FilteredClassLoader(
FilteredClassLoaderTests.class); FilteredClassLoaderTests.class);
try {
this.thrown.expect(ClassNotFoundException.class); this.thrown.expect(ClassNotFoundException.class);
classLoader.loadClass(getClass().getName()); classLoader.loadClass(getClass().getName());
}
finally {
classLoader.close(); classLoader.close();
} }
}
@Test @Test
public void loadClassWhenNotFilteredShouldLoadClass() throws Exception { public void loadClassWhenNotFilteredShouldLoadClass() throws Exception {

@ -72,7 +72,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `getForEntity with reified type parameters, String and URI`() { fun `getForEntity with reified type parameters and URI`() {
val url = URI("https://spring.io") val url = URI("https://spring.io")
template.getForEntity<Foo>(url) template.getForEntity<Foo>(url)
verify(template, times(1)).getForEntity(url, Foo::class.java) verify(template, times(1)).getForEntity(url, Foo::class.java)
@ -88,7 +88,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `getForEntity with reified type parameters and Map`() { fun `getForEntity with reified type parameters, String and Map`() {
val url = "https://spring.io" val url = "https://spring.io"
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
template.getForEntity<Foo>(url, vars) template.getForEntity<Foo>(url, vars)
@ -96,7 +96,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `patchForObject with reified type parameters, String and varargs`() { fun `patchForObject with reified type parameters, String, Any and varargs`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val var1 = "var1" val var1 = "var1"
@ -106,7 +106,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `patchForObject with reified type parameters, String and Map`() { fun `patchForObject with reified type parameters, String, Any and Map`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
@ -115,7 +115,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `patchForObject with reified type parameters`() { fun `patchForObject with reified type parameters, String and Any`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
template.patchForObject<Foo>(url, body) template.patchForObject<Foo>(url, body)
@ -123,7 +123,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForObject with reified type parameters, String and varargs`() { fun `postForObject with reified type parameters, String, Any and varargs`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val var1 = "var1" val var1 = "var1"
@ -133,7 +133,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForObject with reified type parameters, String and Map`() { fun `postForObject with reified type parameters, String, Any and Map`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
@ -142,7 +142,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForObject with reified type parameters`() { fun `postForObject with reified type parameters, String and Any`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
template.postForObject<Foo>(url, body) template.postForObject<Foo>(url, body)
@ -150,7 +150,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForEntity with reified type parameters, String and varargs`() { fun `postForEntity with reified type parameters, String, Any and varargs`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val var1 = "var1" val var1 = "var1"
@ -160,7 +160,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForEntity with reified type parameters, String and Map`() { fun `postForEntity with reified type parameters, String, Any and Map`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
@ -169,7 +169,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `postForEntity with reified type parameters`() { fun `postForEntity with reified type parameters, String and Any`() {
val url = "https://spring.io" val url = "https://spring.io"
val body: Any = "body" val body: Any = "body"
template.postForEntity<Foo>(url, body) template.postForEntity<Foo>(url, body)
@ -210,7 +210,7 @@ class TestRestTemplateExtensionsTests {
} }
@Test @Test
fun `exchange with reified type parameters, String, HttpEntity`() { fun `exchange with reified type parameters and HttpEntity`() {
val entity = mock<RequestEntity<Foo>>() val entity = mock<RequestEntity<Foo>>()
template.exchange<List<Foo>>(entity) template.exchange<List<Foo>>(entity)
verify(template, times(1)).exchange(entity, verify(template, times(1)).exchange(entity,

@ -267,12 +267,12 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId> <artifactId>kotlin-reflect</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId> <artifactId>kotlin-stdlib</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Annotation processing --> <!-- Annotation processing -->

@ -29,7 +29,7 @@ import org.springframework.util.StringUtils;
/** /**
* Utility that can be used to map values from a supplied source to a destination. * Utility that can be used to map values from a supplied source to a destination.
* Primarily intended to be help when mapping from * Primarily intended to be help when mapping from
* {@link ConfigurationProperties @ConfigrationProperties} to third-party classes. * {@link ConfigurationProperties @ConfigurationProperties} to third-party classes.
* <p> * <p>
* Can filter values based on predicates and adapt values if needed. For example: * Can filter values based on predicates and adapt values if needed. For example:
* <pre class="code"> * <pre class="code">
@ -176,7 +176,7 @@ public final class PropertyMapper {
private final Predicate<T> predicate; private final Predicate<T> predicate;
private Source(Supplier<T> supplier, Predicate<T> predicate) { private Source(Supplier<T> supplier, Predicate<T> predicate) {
Assert.notNull(predicate, "Arse"); Assert.notNull(predicate, "Predicate must not be null");
this.supplier = supplier; this.supplier = supplier;
this.predicate = predicate; this.predicate = predicate;
} }

@ -49,9 +49,9 @@ class DurationConverter implements GenericConverter {
TYPES = Collections.unmodifiableSet(types); TYPES = Collections.unmodifiableSet(types);
} }
private static Pattern ISO8601 = Pattern.compile("^[\\+\\-]?P.*$"); private static final Pattern ISO8601 = Pattern.compile("^[\\+\\-]?P.*$");
private static Pattern SIMPLE = Pattern.compile("^([\\+\\-]?\\d+)([a-zA-Z]{0,2})$"); private static final Pattern SIMPLE = Pattern.compile("^([\\+\\-]?\\d+)([a-zA-Z]{0,2})$");
private static final Map<String, ChronoUnit> UNITS; private static final Map<String, ChronoUnit> UNITS;

@ -51,7 +51,6 @@ public class DurationConverterTests {
assertThat(convert("PT10H")).isEqualTo(Duration.parse("PT10H")); assertThat(convert("PT10H")).isEqualTo(Duration.parse("PT10H"));
assertThat(convert("P2D")).isEqualTo(Duration.parse("P2D")); assertThat(convert("P2D")).isEqualTo(Duration.parse("P2D"));
assertThat(convert("P2DT3H4M")).isEqualTo(Duration.parse("P2DT3H4M")); assertThat(convert("P2DT3H4M")).isEqualTo(Duration.parse("P2DT3H4M"));
assertThat(convert("P2DT3H4M")).isEqualTo(Duration.parse("P2DT3H4M"));
assertThat(convert("-PT6H3M")).isEqualTo(Duration.parse("-PT6H3M")); assertThat(convert("-PT6H3M")).isEqualTo(Duration.parse("-PT6H3M"));
assertThat(convert("-PT-6H+3M")).isEqualTo(Duration.parse("-PT-6H+3M")); assertThat(convert("-PT-6H+3M")).isEqualTo(Duration.parse("-PT-6H+3M"));
} }

Loading…
Cancel
Save