From 40ac055d115e68ed5ce7c0c0ff2de5ca3977bb02 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 14 Nov 2019 09:54:50 +0100 Subject: [PATCH] Polish contribution See gh-23895 --- .../datetime/standard/InstantFormatter.java | 3 +- .../standard/InstantFormatterTests.java | 40 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java index 010d004ae5..456c0ad090 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.format.Formatter; * (which is commonly used for HTTP date header values), as of Spring 4.3. * * @author Juergen Hoeller + * @author Andrei Nevedomskii * @since 4.0 * @see java.time.Instant#parse * @see java.time.format.DateTimeFormatter#ISO_INSTANT diff --git a/spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java b/spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java index 5e9b0814fc..3f8dd9c6ad 100644 --- a/spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java +++ b/spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java @@ -16,34 +16,42 @@ package org.springframework.format.datetime.standard; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - import java.text.ParseException; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.Random; import java.util.stream.Stream; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + import static java.time.Instant.MAX; import static java.time.Instant.MIN; import static java.time.ZoneId.systemDefault; import static org.assertj.core.api.Assertions.assertThat; /** + * Unit tests for {@link InstantFormatter}. + * * @author Andrei Nevedomskii + * @author Sam Brannen + * @since 5.1.12 */ -@SuppressWarnings("ConstantConditions") +@DisplayName("InstantFormatter unit tests") +@DisplayNameGeneration(ReplaceUnderscores.class) class InstantFormatterTests { private final InstantFormatter instantFormatter = new InstantFormatter(); @ParameterizedTest @ArgumentsSource(ISOSerializedInstantProvider.class) - void should_parse_an_ISO_formatted_string_representation_of_an_instant(String input) throws ParseException { + void should_parse_an_ISO_formatted_string_representation_of_an_Instant(String input) throws ParseException { Instant expected = DateTimeFormatter.ISO_INSTANT.parse(input, Instant::from); Instant actual = instantFormatter.parse(input, null); @@ -53,7 +61,7 @@ class InstantFormatterTests { @ParameterizedTest @ArgumentsSource(RFC1123SerializedInstantProvider.class) - void should_parse_an_RFC1123_formatted_string_representation_of_an_instant(String input) throws ParseException { + void should_parse_an_RFC1123_formatted_string_representation_of_an_Instant(String input) throws ParseException { Instant expected = DateTimeFormatter.RFC_1123_DATE_TIME.parse(input, Instant::from); Instant actual = instantFormatter.parse(input, null); @@ -63,7 +71,7 @@ class InstantFormatterTests { @ParameterizedTest @ArgumentsSource(RandomInstantProvider.class) - void should_serialize_an_instant_using_ISO_format_and_ignoring_locale(Instant input) { + void should_serialize_an_Instant_using_ISO_format_and_ignoring_Locale(Instant input) { String expected = DateTimeFormatter.ISO_INSTANT.format(input); String actual = instantFormatter.print(input, null); @@ -97,7 +105,7 @@ class InstantFormatterTests { private static final long DATA_SET_SIZE = 10; - static final Random RANDOM = new Random(); + private static final Random random = new Random(); Stream provideArguments() { return randomInstantStream(MIN, MAX); @@ -109,11 +117,9 @@ class InstantFormatterTests { } Stream randomInstantStream(Instant min, Instant max) { - return Stream.concat( - Stream.of(Instant.now()), // make sure that the data set includes current instant - RANDOM.longs(min.getEpochSecond(), max.getEpochSecond()) - .mapToObj(Instant::ofEpochSecond) - ); + return Stream.concat(Stream.of(Instant.now()), // make sure that the data set includes current instant + random.longs(min.getEpochSecond(), max.getEpochSecond()).mapToObj(Instant::ofEpochSecond)); } } -} \ No newline at end of file + +} -- GitLab