diff --git a/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java b/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java index 05b69f7dd7d..60813fc909b 100644 --- a/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java +++ b/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java @@ -29,7 +29,8 @@ import org.springframework.lang.Nullable; /** * Declares that a field or method parameter should be formatted as a - * {@link java.time.Duration}, according to the specified {@link #style style}. + * {@link java.time.Duration}, according to the specified {@link #style Style} + * and {@link #defaultUnit Unit}. * * @author Simon Baslé * @since 6.2 @@ -40,20 +41,20 @@ import org.springframework.lang.Nullable; public @interface DurationFormat { /** - * The {@code Style} to use for parsing and printing a {@code Duration}. + * The {@link Style} to use for parsing and printing a {@link Duration}. *
Defaults to the JDK style ({@link Style#ISO8601}). */ Style style() default Style.ISO8601; /** - * The {@link Unit} to fall back to in case the {@code style()} needs a unit + * The {@link Unit} to fall back to in case the {@link #style Style} needs a unit * for either parsing or printing, and none is explicitly provided in the input. *
Defaults to {@link Unit#MILLIS} if unspecified. */ Unit defaultUnit() default Unit.MILLIS; /** - * Duration format styles. + * {@link Duration} format styles. */ enum Style { @@ -62,7 +63,7 @@ public @interface DurationFormat { *
Supported unit suffixes include: {@code ns, us, ms, s, m, h, d}. * Those correspond to nanoseconds, microseconds, milliseconds, seconds, * minutes, hours, and days, respectively. - *
Note that when printing a {@code Duration}, this style can be + *
Note that when printing a {@link Duration}, this style can be * lossy if the selected unit is bigger than the resolution of the * duration. For example, {@code Duration.ofMillis(5).plusNanos(1234)} * would get truncated to {@code "5ms"} when printing using @@ -73,7 +74,7 @@ public @interface DurationFormat { /** * ISO-8601 formatting. - *
This is what the JDK uses in {@link java.time.Duration#parse(CharSequence)} + *
This is what the JDK uses in {@link Duration#parse(CharSequence)} * and {@link Duration#toString()}. */ ISO8601, @@ -90,11 +91,11 @@ public @interface DurationFormat { } /** - * Duration format unit, which mirrors a subset of {@link ChronoUnit} and + * {@link Duration} format unit, which mirrors a subset of {@link ChronoUnit} and * allows conversion to and from a supported {@code ChronoUnit} as well as * conversion from durations to longs. * - *
The enum includes its corresponding suffix in the {@link Style#SIMPLE simple} + *
The enum includes its corresponding suffix in the {@link Style#SIMPLE SIMPLE} * {@code Duration} format style. */ enum Unit { @@ -147,25 +148,24 @@ public @interface DurationFormat { } /** - * Convert this {@code DurationFormat.Unit} to its {@link ChronoUnit} - * equivalent. + * Convert this {@code Unit} to its {@link ChronoUnit} equivalent. */ public ChronoUnit asChronoUnit() { return this.chronoUnit; } /** - * Convert this {@code DurationFormat.Unit} to a simple {@code String} - * suffix, suitable for the {@link Style#SIMPLE SIMPLE} style. + * Convert this {@code Unit} to a simple {@code String} suffix, suitable + * for the {@link Style#SIMPLE SIMPLE} style. */ public String asSuffix() { return this.suffix; } /** - * Parse a {@code long} from a {@code String} and interpret it to be a - * {@code Duration} in the current unit. - * @param value the String representation of the long + * Parse a {@code long} from the given {@link String} and interpret it to be a + * {@link Duration} in the current unit. + * @param value the {@code String} representation of the long * @return the corresponding {@code Duration} */ public Duration parse(String value) { @@ -173,11 +173,11 @@ public @interface DurationFormat { } /** - * Print a {@code Duration} as a {@code String}, converting it to a long + * Print the given {@link Duration} as a {@link String}, converting it to a long * value using this unit's precision via {@link #longValue(Duration)} * and appending this unit's simple {@link #asSuffix() suffix}. - * @param value the {@code Duration} to convert to a String - * @return the String representation of the {@code Duration} in the + * @param value the {@code Duration} to convert to a {@code String} + * @return the {@code String} representation of the {@code Duration} in the * {@link Style#SIMPLE SIMPLE} style */ public String print(Duration value) { @@ -185,11 +185,12 @@ public @interface DurationFormat { } /** - * Convert the given {@code Duration} to a long value in the resolution - * of this unit. Note that this can be lossy if the current unit is - * bigger than the actual resolution of the duration. - *
For example, {@code Duration.ofMillis(5).plusNanos(1234)} would - * get truncated to {@code 5} for unit {@code MILLIS}. + * Convert the given {@link Duration} to a long value in the resolution + * of this unit. + *
Note that this can be lossy if the current unit is bigger than the
+ * actual resolution of the duration. For example,
+ * {@code Duration.ofMillis(5).plusNanos(1234)} would get truncated to
+ * {@code 5} for unit {@code MILLIS}.
* @param value the {@code Duration} to convert to a long
* @return the long value for the {@code Duration} in this {@code Unit}
*/
@@ -198,7 +199,7 @@ public @interface DurationFormat {
}
/**
- * Get the {@code Unit} corresponding to the given {@code ChronoUnit}.
+ * Get the {@link Unit} corresponding to the given {@link ChronoUnit}.
* @throws IllegalArgumentException if the given {@code ChronoUnit} is
* not supported
*/
@@ -215,7 +216,7 @@ public @interface DurationFormat {
}
/**
- * Get the {@code Unit} corresponding to the given {@code String} suffix.
+ * Get the {@link Unit} corresponding to the given {@link String} suffix.
* @throws IllegalArgumentException if the given suffix is not supported
*/
public static Unit fromSuffix(String suffix) {
diff --git a/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java b/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java
index 6a4a17931e6..a446d347dd0 100644
--- a/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java
+++ b/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java
@@ -42,7 +42,7 @@ import static org.springframework.format.annotation.DurationFormat.Style.SIMPLE;
class DurationFormatterUtilsTests {
@ParameterizedTest
- @EnumSource(DurationFormat.Style.class)
+ @EnumSource
void parseEmptyStringFailsWithDedicatedException(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse("", style))
@@ -50,7 +50,7 @@ class DurationFormatterUtilsTests {
}
@ParameterizedTest
- @EnumSource(DurationFormat.Style.class)
+ @EnumSource
void parseNullStringFailsWithDedicatedException(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse(null, style))
@@ -113,29 +113,30 @@ class DurationFormatterUtilsTests {
@Test
void parseIsoNoChronoUnit() {
- //these are based on the examples given in Duration.parse
-// "PT20.345S" -- parses as "20.345 seconds"
+ // These are based on the examples given in Duration.parse.
+
+ // "PT20.345S" -- parses as "20.345 seconds"
assertThat(DurationFormatterUtils.parse("PT20.345S", ISO8601))
.hasMillis(20345);
-// "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
+ // "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
assertThat(DurationFormatterUtils.parse("PT15M", ISO8601))
.hasSeconds(15*60);
-// "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
+ // "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
assertThat(DurationFormatterUtils.parse("PT10H", ISO8601))
.hasHours(10);
-// "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+ // "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
assertThat(DurationFormatterUtils.parse("P2D", ISO8601))
.hasDays(2);
-// "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
+ // "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
assertThat(DurationFormatterUtils.parse("P2DT3H4M", ISO8601))
.isEqualTo(Duration.ofDays(2).plusHours(3).plusMinutes(4));
-// "PT-6H3M" -- parses as "-6 hours and +3 minutes"
+ // "PT-6H3M" -- parses as "-6 hours and +3 minutes"
assertThat(DurationFormatterUtils.parse("PT-6H3M", ISO8601))
.isEqualTo(Duration.ofHours(-6).plusMinutes(3));
-// "-PT6H3M" -- parses as "-6 hours and -3 minutes"
+ // "-PT6H3M" -- parses as "-6 hours and -3 minutes"
assertThat(DurationFormatterUtils.parse("-PT6H3M", ISO8601))
.isEqualTo(Duration.ofHours(-6).plusMinutes(-3));
-// "-PT-6H+3M" -- parses as "+6 hours and -3 minutes"
+ // "-PT-6H+3M" -- parses as "+6 hours and -3 minutes"
assertThat(DurationFormatterUtils.parse("-PT-6H+3M", ISO8601))
.isEqualTo(Duration.ofHours(6).plusMinutes(-3));
}
@@ -189,7 +190,7 @@ class DurationFormatterUtilsTests {
.isEqualTo(Duration.ofMinutes(34).plusSeconds(57));
}
- @Test //Kotlin style compatibility
+ @Test // Kotlin style compatibility
void parseCompositeNegativeWithSpacesAndParenthesis() {
assertThat(DurationFormatterUtils.parse("-(34m 57s)", COMPOSITE))
.isEqualTo(Duration.ofMinutes(-34).plusSeconds(-57));
@@ -315,7 +316,7 @@ class DurationFormatterUtilsTests {
assertThat(DurationFormatterUtils.detect("-(1d 2h 34m 2ns)"))
.as("COMPOSITE")
- .isEqualTo(COMPOSITE);
+ .isEqualTo(COMPOSITE);
assertThatIllegalArgumentException().isThrownBy(() -> DurationFormatterUtils.detect("WPT2H-4M"))
.withMessage("'WPT2H-4M' is not a valid duration, cannot detect any known style")
diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java
index 92318bc2531..ada94f94e8e 100644
--- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java
+++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java
@@ -67,7 +67,7 @@ class H2SequenceMaxValueIncrementerTests {
* Tests that the incrementer works when using all supported H2 compatibility modes.
*/
@ParameterizedTest
- @EnumSource(ModeEnum.class)
+ @EnumSource
void incrementsSequenceWithExplicitH2CompatibilityMode(ModeEnum mode) {
String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s", UUID.randomUUID(), mode);
DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");
diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java
index 4fcc9829eae..3a836863336 100644
--- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java
+++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2023 the original author or authors.
+ * Copyright 2002-2024 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.
diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
index 0ee05235fb4..ce22e8e4c88 100644
--- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
+++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
@@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
class UriComponentsBuilderTests {
@ParameterizedTest // see gh-26453
- @EnumSource(value = ParserType.class)
+ @EnumSource
void examplesInReferenceManual(ParserType parserType) {
final String expected = "/hotel%20list/New%20York?q=foo%2Bbar";
@@ -156,7 +156,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see gh-9317
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriEncodedQuery(ParserType parserType) {
URI uri = URI.create("https://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
@@ -167,7 +167,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriString(ParserType parserType) {
UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt", parserType).build();
assertThat(result.getScheme()).isEqualTo("https");
@@ -224,7 +224,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-9832
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriStringQueryParamWithReservedCharInValue(ParserType parserType) {
String uri = "https://www.google.com/ig/calculator?q=1USD=?EUR";
UriComponents result = UriComponentsBuilder.fromUriString(uri, parserType).build();
@@ -234,7 +234,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-14828
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriStringQueryParamEncodedAndContainingPlus(ParserType parserType) {
String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98";
URI uri = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(true).toUri();
@@ -243,7 +243,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-10539
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriStringIPv6Host(ParserType parserType) {
UriComponents result = UriComponentsBuilder
.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource", parserType).build().encode();
@@ -251,14 +251,14 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriStringInvalidIPv6Host(ParserType parserType) {
assertThatIllegalArgumentException().isThrownBy(() ->
UriComponentsBuilder.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType));
}
@ParameterizedTest // see SPR-11970
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromUriStringNoPathWithReservedCharInQuery(ParserType parserType) {
UriComponents result = UriComponentsBuilder.fromUriString("https://example.com?foo=bar@baz", parserType).build();
assertThat(result.getUserInfo()).isNull();
@@ -268,7 +268,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-1428
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromHttpUrlQueryParamEncodedAndContainingPlus(ParserType parserType) {
String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98";
URI uri = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(true).toUri();
@@ -277,7 +277,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-10779
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromHttpUrlCaseInsensitiveScheme(ParserType parserType) {
assertThat(UriComponentsBuilder.fromUriString("HTTP://www.google.com", parserType).build().getScheme())
.isEqualTo("http");
@@ -286,14 +286,14 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see SPR-10539
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromHttpUrlInvalidIPv6Host(ParserType parserType) {
assertThatIllegalArgumentException().isThrownBy(() ->
UriComponentsBuilder.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType));
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromHttpUrlWithoutFragment(ParserType parserType) {
String httpUrl = "http://localhost:8080/test/print";
UriComponents uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build();
@@ -333,7 +333,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // see gh-25300
- @EnumSource(value = ParserType.class)
+ @EnumSource
void fromHttpUrlWithFragment(ParserType parserType) {
String httpUrl = "https://example.com/#baz";
UriComponents uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build();
@@ -449,7 +449,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void replacePath(ParserType parserType) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc2396.txt", parserType);
builder.replacePath("/rfc/rfc3986.txt");
@@ -465,7 +465,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void replaceQuery(ParserType parserType) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar&baz=qux", parserType);
builder.replaceQuery("baz=42");
@@ -605,7 +605,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void parseBuildAndExpandHierarchical(ParserType parserType) {
URI uri = UriComponentsBuilder
.fromUriString("{scheme}://{host}:{port}/{segment}?{query}#{fragment}", parserType)
@@ -617,7 +617,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest
- @EnumSource(value = ParserType.class)
+ @EnumSource
void buildAndExpandOpaque(ParserType parserType) {
UriComponents result = UriComponentsBuilder.fromUriString("mailto:{user}@{domain}", parserType)
.buildAndExpand("foo", "example.com");
@@ -631,7 +631,7 @@ class UriComponentsBuilderTests {
}
@ParameterizedTest // gh-33699
- @EnumSource(value = ParserType.class)
+ @EnumSource
void schemeVariableMixedCase(ParserType parserType) {
BiConsumer