Skip to content

Commit 0bc01fc

Browse files
committed
Polishing
1 parent 7a8d41e commit 0bc01fc

File tree

5 files changed

+35
-37
lines changed

5 files changed

+35
-37
lines changed

spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
import java.time.LocalDateTime;
2525

2626
import org.junit.Test;
27+
2728
import org.springframework.core.convert.support.DefaultConversionService;
2829
import org.springframework.dao.TypeMismatchDataAccessException;
2930

30-
import static org.mockito.BDDMockito.*;
3131
import static org.junit.Assert.*;
32+
import static org.mockito.BDDMockito.*;
3233

3334
/**
3435
* Tests for {@link SingleColumnRowMapper}.
@@ -38,7 +39,7 @@
3839
*/
3940
public class SingleColumnRowMapperTests {
4041

41-
@Test // SPR-16483
42+
@Test // SPR-16483
4243
public void useDefaultConversionService() throws SQLException {
4344
Timestamp timestamp = new Timestamp(0);
4445

@@ -57,7 +58,7 @@ public void useDefaultConversionService() throws SQLException {
5758
assertEquals(timestamp.toLocalDateTime(), actualLocalDateTime);
5859
}
5960

60-
@Test // SPR-16483
61+
@Test // SPR-16483
6162
public void useCustomConversionService() throws SQLException {
6263
Timestamp timestamp = new Timestamp(0);
6364

@@ -81,7 +82,7 @@ public void useCustomConversionService() throws SQLException {
8182
assertEquals(timestamp.toLocalDateTime(), actualMyLocalDateTime.value);
8283
}
8384

84-
@Test(expected = TypeMismatchDataAccessException.class) // SPR-16483
85+
@Test(expected = TypeMismatchDataAccessException.class) // SPR-16483
8586
public void doesNotUseConversionService() throws SQLException {
8687
SingleColumnRowMapper<LocalDateTime> rowMapper =
8788
SingleColumnRowMapper.newInstance(LocalDateTime.class, null);
@@ -97,9 +98,12 @@ public void doesNotUseConversionService() throws SQLException {
9798
rowMapper.mapRow(resultSet, 1);
9899
}
99100

101+
100102
private static class MyLocalDateTime {
103+
101104
private final LocalDateTime value;
102-
private MyLocalDateTime(LocalDateTime value) {
105+
106+
public MyLocalDateTime(LocalDateTime value) {
103107
this.value = value;
104108
}
105109
}

spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,10 +126,8 @@ else if (isEligibleForEtag(request, responseWrapper, statusCode, responseWrapper
126126
String responseETag = generateETagHeaderValue(responseWrapper.getContentInputStream(), this.writeWeakETag);
127127
rawResponse.setHeader(HEADER_ETAG, responseETag);
128128
String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
129-
if (requestETag != null
130-
&& (responseETag.equals(requestETag)
131-
|| responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", ""))
132-
|| "*".equals(requestETag))) {
129+
if (requestETag != null && ("*".equals(requestETag) || responseETag.equals(requestETag) ||
130+
responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", "")))) {
133131
if (logger.isTraceEnabled()) {
134132
logger.trace("ETag [" + responseETag + "] equal to If-None-Match, sending 304");
135133
}
@@ -163,19 +161,15 @@ else if (isEligibleForEtag(request, responseWrapper, statusCode, responseWrapper
163161
* @param response the HTTP response
164162
* @param responseStatusCode the HTTP response status code
165163
* @param inputStream the response body
166-
* @return {@code true} if eligible for ETag generation; {@code false} otherwise
164+
* @return {@code true} if eligible for ETag generation, {@code false} otherwise
167165
*/
168166
protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response,
169167
int responseStatusCode, InputStream inputStream) {
170168

171169
String method = request.getMethod();
172-
if (responseStatusCode >= 200 && responseStatusCode < 300
173-
&& HttpMethod.GET.matches(method)) {
174-
170+
if (responseStatusCode >= 200 && responseStatusCode < 300 && HttpMethod.GET.matches(method)) {
175171
String cacheControl = response.getHeader(HEADER_CACHE_CONTROL);
176-
if (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)) {
177-
return true;
178-
}
172+
return (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE));
179173
}
180174
return false;
181175
}
@@ -189,7 +183,7 @@ protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletRespo
189183
* @see org.springframework.util.DigestUtils
190184
*/
191185
protected String generateETagHeaderValue(InputStream inputStream, boolean isWeak) throws IOException {
192-
// length of W/ + 0 + " + 32bits md5 hash + "
186+
// length of W/ + " + 0 + 32bits md5 hash + "
193187
StringBuilder builder = new StringBuilder(37);
194188
if (isWeak) {
195189
builder.append("W/");

src/docs/asciidoc/core/core-validation.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ The `number` package provides a `NumberFormatter`, `CurrencyFormatter`, and
11061106
`PercentFormatter` to format `java.lang.Number` objects using a `java.text.NumberFormat`.
11071107
The `datetime` package provides a `DateFormatter` to format `java.util.Date` objects with
11081108
a `java.text.DateFormat`. The `datetime.joda` package provides comprehensive datetime
1109-
formatting support based on the http://joda-time.sourceforge.net[Joda Time library].
1109+
formatting support based on the http://joda-time.sourceforge.net[Joda-Time library].
11101110

11111111
Consider `DateFormatter` as an example `Formatter` implementation:
11121112

@@ -1240,7 +1240,7 @@ To trigger formatting, simply annotate fields with @NumberFormat:
12401240

12411241
A portable format annotation API exists in the `org.springframework.format.annotation`
12421242
package. Use @NumberFormat to format java.lang.Number fields. Use @DateTimeFormat to
1243-
format java.util.Date, java.util.Calendar, java.util.Long, or Joda Time fields.
1243+
format java.util.Date, java.util.Calendar, java.util.Long, or Joda-Time fields.
12441244

12451245
The example below uses @DateTimeFormat to format a java.util.Date as a ISO Date
12461246
(yyyy-MM-dd):
@@ -1344,10 +1344,10 @@ You will need to ensure that Spring does not register default formatters, and in
13441344
you should register all formatters manually. Use the
13451345
`org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar` or
13461346
`org.springframework.format.datetime.DateFormatterRegistrar` class depending on whether
1347-
you use the Joda Time library.
1347+
you use the Joda-Time library.
13481348

13491349
For example, the following Java configuration will register a global ' `yyyyMMdd`'
1350-
format. This example does not depend on the Joda Time library:
1350+
format. This example does not depend on the Joda-Time library:
13511351

13521352
[source,java,indent=0]
13531353
[subs="verbatim,quotes"]
@@ -1412,7 +1412,7 @@ Time:
14121412

14131413
[NOTE]
14141414
====
1415-
Joda Time provides separate distinct types to represent `date`, `time` and `date-time`
1415+
Joda-Time provides separate distinct types to represent `date`, `time` and `date-time`
14161416
values. The `dateFormatter`, `timeFormatter` and `dateTimeFormatter` properties of the
14171417
`JodaTimeFormatterRegistrar` should be used to configure the different formats for each
14181418
type. The `DateTimeFormatterFactoryBean` provides a convenient way to create formatters.

src/docs/asciidoc/web/webflux.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,8 @@ In your Java config implement the `WebFluxConfigurer` interface:
24522452
[.small]#<<web.adoc#mvc-config-conversion,Same in Spring MVC>>#
24532453

24542454
By default formatters for `Number` and `Date` types are installed, including support for
2455-
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda Time
2456-
formatting library is also installed if Joda Time is present on the classpath.
2455+
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time
2456+
formatting library is also installed if Joda-Time is present on the classpath.
24572457

24582458
To register custom formatters and converters:
24592459

src/docs/asciidoc/web/webmvc.adoc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ The table below lists the special beans detected by the `DispatcherHandler`:
277277
=== Web MVC Config
278278
[.small]#<<web-reactive.adoc#webflux-framework-config,Same in Spring WebFlux>>#
279279

280-
Applications can declare the infrastructure beans listed in <<mvc-special-bean-types>>
280+
Applications can declare the infrastructure beans listed in <<mvc-servlet-special-bean-types>>
281281
that are required to process requests. The `DispatcherServlet` checks the
282-
`WebApplicationContext` for each special bean. If there are no matching bean types, it
283-
falls back on the default types listed in
282+
`WebApplicationContext` for each special bean. If there are no matching bean types,
283+
it falls back on the default types listed in
284284
https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[DispatcherServlet.properties].
285285

286286
In most cases the <<mvc-config>> is the best starting point. It declares the required
@@ -3733,9 +3733,9 @@ applications along with a configuration API to customize it.
37333733
For more advanced customizations, not available in the configuration API, see
37343734
<<mvc-config-advanced-java>> and <<mvc-config-advanced-xml>>.
37353735

3736-
You do not need to understand the underlying beans created by the MVC Java config and the
3737-
MVC namespace but if you want to learn more, see <<mvc-servlet-special-bean-types>> and
3738-
<<mvc-servlet-config>>.
3736+
You do not need to understand the underlying beans created by the MVC Java config and
3737+
the MVC namespace but if you want to learn more, see <<mvc-servlet-special-bean-types>>
3738+
and <<mvc-servlet-config>>.
37393739

37403740

37413741
[[mvc-config-enable]]
@@ -3796,10 +3796,10 @@ In Java config implement `WebMvcConfigurer` interface:
37963796
}
37973797
----
37983798

3799-
In XML check attributes and sub-elements of `<mvc:annotation-driven/>`. You can view the
3800-
http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use the code
3801-
completion feature of your IDE to discover what attributes and sub-elements are
3802-
available.
3799+
In XML check attributes and sub-elements of `<mvc:annotation-driven/>`. You can
3800+
view the http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use
3801+
the code completion feature of your IDE to discover what attributes and
3802+
sub-elements are available.
38033803

38043804

38053805

@@ -3808,8 +3808,8 @@ available.
38083808
[.small]#<<web-reactive.adoc#webflux-config-conversion,Same in Spring WebFlux>>#
38093809

38103810
By default formatters for `Number` and `Date` types are installed, including support for
3811-
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda Time
3812-
formatting library is also installed if Joda Time is present on the classpath.
3811+
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time
3812+
formatting library is also installed if Joda-Time is present on the classpath.
38133813

38143814
In Java config, register custom formatters and converters:
38153815

0 commit comments

Comments
 (0)