1
1
/*
2
- * Copyright 2012-2021 the original author or authors.
2
+ * Copyright 2012-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
* Tests for {@link DurationStyle}.
29
29
*
30
30
* @author Phillip Webb
31
+ * @author Valentine Wu
31
32
*/
32
33
class DurationStyleTests {
33
34
@@ -39,6 +40,7 @@ void detectAndParseWhenValueIsNullShouldThrowException() {
39
40
40
41
@ Test
41
42
void detectAndParseWhenIso8601ShouldReturnDuration () {
43
+ assertThat (DurationStyle .detectAndParse ("pt20.345s" )).isEqualTo (Duration .parse ("pt20.345s" ));
42
44
assertThat (DurationStyle .detectAndParse ("PT20.345S" )).isEqualTo (Duration .parse ("PT20.345S" ));
43
45
assertThat (DurationStyle .detectAndParse ("PT15M" )).isEqualTo (Duration .parse ("PT15M" ));
44
46
assertThat (DurationStyle .detectAndParse ("+PT15M" )).isEqualTo (Duration .parse ("PT15M" ));
@@ -143,6 +145,7 @@ void detectWhenSimpleShouldReturnSimple() {
143
145
144
146
@ Test
145
147
void detectWhenIso8601ShouldReturnIso8601 () {
148
+ assertThat (DurationStyle .detect ("pt20.345s" )).isEqualTo (DurationStyle .ISO8601 );
146
149
assertThat (DurationStyle .detect ("PT20.345S" )).isEqualTo (DurationStyle .ISO8601 );
147
150
assertThat (DurationStyle .detect ("PT15M" )).isEqualTo (DurationStyle .ISO8601 );
148
151
assertThat (DurationStyle .detect ("+PT15M" )).isEqualTo (DurationStyle .ISO8601 );
@@ -161,6 +164,7 @@ void detectWhenUnknownShouldThrowException() {
161
164
162
165
@ Test
163
166
void parseIso8601ShouldParse () {
167
+ assertThat (DurationStyle .ISO8601 .parse ("pt20.345s" )).isEqualTo (Duration .parse ("pt20.345s" ));
164
168
assertThat (DurationStyle .ISO8601 .parse ("PT20.345S" )).isEqualTo (Duration .parse ("PT20.345S" ));
165
169
assertThat (DurationStyle .ISO8601 .parse ("PT15M" )).isEqualTo (Duration .parse ("PT15M" ));
166
170
assertThat (DurationStyle .ISO8601 .parse ("+PT15M" )).isEqualTo (Duration .parse ("PT15M" ));
@@ -173,6 +177,7 @@ void parseIso8601ShouldParse() {
173
177
174
178
@ Test
175
179
void parseIso8601WithUnitShouldIgnoreUnit () {
180
+ assertThat (DurationStyle .ISO8601 .parse ("pt20.345s" , ChronoUnit .SECONDS )).isEqualTo (Duration .parse ("pt20.345s" ));
176
181
assertThat (DurationStyle .ISO8601 .parse ("PT20.345S" , ChronoUnit .SECONDS )).isEqualTo (Duration .parse ("PT20.345S" ));
177
182
assertThat (DurationStyle .ISO8601 .parse ("PT15M" , ChronoUnit .SECONDS )).isEqualTo (Duration .parse ("PT15M" ));
178
183
assertThat (DurationStyle .ISO8601 .parse ("+PT15M" , ChronoUnit .SECONDS )).isEqualTo (Duration .parse ("PT15M" ));
0 commit comments