mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
Closes gh-11372
This commit is contained in:
parent
873d88e1eb
commit
e4f0ad2165
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
import org.springframework.http.CacheControl;
|
||||
|
||||
/**
|
||||
* Properties used to configure resource handling.
|
||||
@ -458,9 +459,9 @@ public class ResourceProperties {
|
||||
this.sMaxAge = sMaxAge;
|
||||
}
|
||||
|
||||
public org.springframework.http.CacheControl toHttpCacheControl() {
|
||||
public CacheControl toHttpCacheControl() {
|
||||
PropertyMapper map = PropertyMapper.get();
|
||||
org.springframework.http.CacheControl control = createCacheControl();
|
||||
CacheControl control = createCacheControl();
|
||||
map.from(this::getMustRevalidate).whenTrue()
|
||||
.toCall(control::mustRevalidate);
|
||||
map.from(this::getNoTransform).whenTrue().toCall(control::noTransform);
|
||||
@ -478,18 +479,18 @@ public class ResourceProperties {
|
||||
return control;
|
||||
}
|
||||
|
||||
private org.springframework.http.CacheControl createCacheControl() {
|
||||
private CacheControl createCacheControl() {
|
||||
if (Boolean.TRUE.equals(this.noStore)) {
|
||||
return org.springframework.http.CacheControl.noStore();
|
||||
return CacheControl.noStore();
|
||||
}
|
||||
if (Boolean.TRUE.equals(this.noCache)) {
|
||||
return org.springframework.http.CacheControl.noCache();
|
||||
return CacheControl.noCache();
|
||||
}
|
||||
if (this.maxAge != null) {
|
||||
return org.springframework.http.CacheControl
|
||||
return CacheControl
|
||||
.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.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
|
||||
@ -457,7 +456,7 @@ public class JacksonAutoConfigurationTests {
|
||||
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
|
||||
DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
|
||||
String expected = FormatConfig.DEFAULT_DATETIME_PRINTER.rawFormatter()
|
||||
.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC")))
|
||||
.withZone(DateTimeZone.UTC)
|
||||
.print(dateTime);
|
||||
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.testsupport.assertj.Matched;
|
||||
import org.springframework.http.CacheControl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.endsWith;
|
||||
@ -73,7 +74,7 @@ public class ResourcePropertiesTests {
|
||||
|
||||
@Test
|
||||
public void emptyCacheControl() {
|
||||
org.springframework.http.CacheControl cacheControl = this.properties.getCache()
|
||||
CacheControl cacheControl = this.properties.getCache()
|
||||
.getCachecontrol().toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isNull();
|
||||
}
|
||||
@ -90,8 +91,7 @@ public class ResourcePropertiesTests {
|
||||
properties.setSMaxAge(Duration.ofSeconds(5));
|
||||
properties.setStaleIfError(Duration.ofSeconds(6));
|
||||
properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
|
||||
org.springframework.http.CacheControl cacheControl = properties
|
||||
.toHttpCacheControl();
|
||||
CacheControl cacheControl = properties.toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isEqualTo(
|
||||
"max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
|
||||
+ " 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();
|
||||
properties.setMaxAge(Duration.ofSeconds(4));
|
||||
properties.setNoStore(true);
|
||||
org.springframework.http.CacheControl cacheControl = properties
|
||||
.toHttpCacheControl();
|
||||
CacheControl cacheControl = properties.toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,13 @@ public class FilteredClassLoaderTests {
|
||||
public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception {
|
||||
FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
FilteredClassLoaderTests.class);
|
||||
this.thrown.expect(ClassNotFoundException.class);
|
||||
classLoader.loadClass(getClass().getName());
|
||||
classLoader.close();
|
||||
try {
|
||||
this.thrown.expect(ClassNotFoundException.class);
|
||||
classLoader.loadClass(getClass().getName());
|
||||
}
|
||||
finally {
|
||||
classLoader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,7 +72,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForEntity with reified type parameters, String and URI`() {
|
||||
fun `getForEntity with reified type parameters and URI`() {
|
||||
val url = URI("https://spring.io")
|
||||
template.getForEntity<Foo>(url)
|
||||
verify(template, times(1)).getForEntity(url, Foo::class.java)
|
||||
@ -88,7 +88,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForEntity with reified type parameters and Map`() {
|
||||
fun `getForEntity with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.getForEntity<Foo>(url, vars)
|
||||
@ -96,7 +96,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val var1 = "var1"
|
||||
@ -106,7 +106,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
@ -115,7 +115,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `patchForObject with reified type parameters`() {
|
||||
fun `patchForObject with reified type parameters, String and Any`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.patchForObject<Foo>(url, body)
|
||||
@ -123,7 +123,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val var1 = "var1"
|
||||
@ -133,7 +133,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
@ -142,7 +142,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForObject with reified type parameters`() {
|
||||
fun `postForObject with reified type parameters, String and Any`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForObject<Foo>(url, body)
|
||||
@ -150,7 +150,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val var1 = "var1"
|
||||
@ -160,7 +160,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@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 body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
@ -169,7 +169,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters`() {
|
||||
fun `postForEntity with reified type parameters, String and Any`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForEntity<Foo>(url, body)
|
||||
@ -210,7 +210,7 @@ class TestRestTemplateExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpEntity`() {
|
||||
fun `exchange with reified type parameters and HttpEntity`() {
|
||||
val entity = mock<RequestEntity<Foo>>()
|
||||
template.exchange<List<Foo>>(entity)
|
||||
verify(template, times(1)).exchange(entity,
|
||||
|
@ -267,12 +267,12 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- 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.
|
||||
* Primarily intended to be help when mapping from
|
||||
* {@link ConfigurationProperties @ConfigrationProperties} to third-party classes.
|
||||
* {@link ConfigurationProperties @ConfigurationProperties} to third-party classes.
|
||||
* <p>
|
||||
* Can filter values based on predicates and adapt values if needed. For example:
|
||||
* <pre class="code">
|
||||
@ -176,7 +176,7 @@ public final class PropertyMapper {
|
||||
private final 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.predicate = predicate;
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ class DurationConverter implements GenericConverter {
|
||||
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;
|
||||
|
||||
|
@ -51,7 +51,6 @@ public class DurationConverterTests {
|
||||
assertThat(convert("PT10H")).isEqualTo(Duration.parse("PT10H"));
|
||||
assertThat(convert("P2D")).isEqualTo(Duration.parse("P2D"));
|
||||
assertThat(convert("P2DT3H4M")).isEqualTo(Duration.parse("P2DT3H4M"));
|
||||
assertThat(convert("P2DT3H4M")).isEqualTo(Duration.parse("P2DT3H4M"));
|
||||
assertThat(convert("-PT6H3M")).isEqualTo(Duration.parse("-PT6H3M"));
|
||||
assertThat(convert("-PT-6H+3M")).isEqualTo(Duration.parse("-PT-6H+3M"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user