Skip to content

Commit 40ac055

Browse files
committed
Polish contribution
See gh-23895
1 parent c9a6f42 commit 40ac055

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -31,6 +31,7 @@
3131
* (which is commonly used for HTTP date header values), as of Spring 4.3.
3232
*
3333
* @author Juergen Hoeller
34+
* @author Andrei Nevedomskii
3435
* @since 4.0
3536
* @see java.time.Instant#parse
3637
* @see java.time.format.DateTimeFormatter#ISO_INSTANT

spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,42 @@
1616

1717
package org.springframework.format.datetime.standard;
1818

19-
import org.junit.jupiter.api.extension.ExtensionContext;
20-
import org.junit.jupiter.params.ParameterizedTest;
21-
import org.junit.jupiter.params.provider.Arguments;
22-
import org.junit.jupiter.params.provider.ArgumentsProvider;
23-
import org.junit.jupiter.params.provider.ArgumentsSource;
24-
2519
import java.text.ParseException;
2620
import java.time.Instant;
2721
import java.time.format.DateTimeFormatter;
2822
import java.util.Random;
2923
import java.util.stream.Stream;
3024

25+
import org.junit.jupiter.api.DisplayName;
26+
import org.junit.jupiter.api.DisplayNameGeneration;
27+
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
28+
import org.junit.jupiter.api.extension.ExtensionContext;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.Arguments;
31+
import org.junit.jupiter.params.provider.ArgumentsProvider;
32+
import org.junit.jupiter.params.provider.ArgumentsSource;
33+
3134
import static java.time.Instant.MAX;
3235
import static java.time.Instant.MIN;
3336
import static java.time.ZoneId.systemDefault;
3437
import static org.assertj.core.api.Assertions.assertThat;
3538

3639
/**
40+
* Unit tests for {@link InstantFormatter}.
41+
*
3742
* @author Andrei Nevedomskii
43+
* @author Sam Brannen
44+
* @since 5.1.12
3845
*/
39-
@SuppressWarnings("ConstantConditions")
46+
@DisplayName("InstantFormatter unit tests")
47+
@DisplayNameGeneration(ReplaceUnderscores.class)
4048
class InstantFormatterTests {
4149

4250
private final InstantFormatter instantFormatter = new InstantFormatter();
4351

4452
@ParameterizedTest
4553
@ArgumentsSource(ISOSerializedInstantProvider.class)
46-
void should_parse_an_ISO_formatted_string_representation_of_an_instant(String input) throws ParseException {
54+
void should_parse_an_ISO_formatted_string_representation_of_an_Instant(String input) throws ParseException {
4755
Instant expected = DateTimeFormatter.ISO_INSTANT.parse(input, Instant::from);
4856

4957
Instant actual = instantFormatter.parse(input, null);
@@ -53,7 +61,7 @@ void should_parse_an_ISO_formatted_string_representation_of_an_instant(String in
5361

5462
@ParameterizedTest
5563
@ArgumentsSource(RFC1123SerializedInstantProvider.class)
56-
void should_parse_an_RFC1123_formatted_string_representation_of_an_instant(String input) throws ParseException {
64+
void should_parse_an_RFC1123_formatted_string_representation_of_an_Instant(String input) throws ParseException {
5765
Instant expected = DateTimeFormatter.RFC_1123_DATE_TIME.parse(input, Instant::from);
5866

5967
Instant actual = instantFormatter.parse(input, null);
@@ -63,7 +71,7 @@ void should_parse_an_RFC1123_formatted_string_representation_of_an_instant(Strin
6371

6472
@ParameterizedTest
6573
@ArgumentsSource(RandomInstantProvider.class)
66-
void should_serialize_an_instant_using_ISO_format_and_ignoring_locale(Instant input) {
74+
void should_serialize_an_Instant_using_ISO_format_and_ignoring_Locale(Instant input) {
6775
String expected = DateTimeFormatter.ISO_INSTANT.format(input);
6876

6977
String actual = instantFormatter.print(input, null);
@@ -97,7 +105,7 @@ private static class RandomInstantProvider implements ArgumentsProvider {
97105

98106
private static final long DATA_SET_SIZE = 10;
99107

100-
static final Random RANDOM = new Random();
108+
private static final Random random = new Random();
101109

102110
Stream<?> provideArguments() {
103111
return randomInstantStream(MIN, MAX);
@@ -109,11 +117,9 @@ public final Stream<? extends Arguments> provideArguments(ExtensionContext conte
109117
}
110118

111119
Stream<Instant> randomInstantStream(Instant min, Instant max) {
112-
return Stream.concat(
113-
Stream.of(Instant.now()), // make sure that the data set includes current instant
114-
RANDOM.longs(min.getEpochSecond(), max.getEpochSecond())
115-
.mapToObj(Instant::ofEpochSecond)
116-
);
120+
return Stream.concat(Stream.of(Instant.now()), // make sure that the data set includes current instant
121+
random.longs(min.getEpochSecond(), max.getEpochSecond()).mapToObj(Instant::ofEpochSecond));
117122
}
118123
}
119-
}
124+
125+
}

0 commit comments

Comments
 (0)