|
1 | 1 | /* |
2 | | - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 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. |
@@ -51,72 +51,72 @@ void detectAndParseWhenIso8601ShouldReturnDuration() { |
51 | 51 |
|
52 | 52 | @Test |
53 | 53 | void detectAndParseWhenSimpleNanosShouldReturnDuration() { |
54 | | - assertThat(DurationStyle.detectAndParse("10ns")).isEqualTo(Duration.ofNanos(10)); |
55 | | - assertThat(DurationStyle.detectAndParse("10NS")).isEqualTo(Duration.ofNanos(10)); |
56 | | - assertThat(DurationStyle.detectAndParse("+10ns")).isEqualTo(Duration.ofNanos(10)); |
57 | | - assertThat(DurationStyle.detectAndParse("-10ns")).isEqualTo(Duration.ofNanos(-10)); |
| 54 | + assertThat(DurationStyle.detectAndParse("10ns")).hasNanos(10); |
| 55 | + assertThat(DurationStyle.detectAndParse("10NS")).hasNanos(10); |
| 56 | + assertThat(DurationStyle.detectAndParse("+10ns")).hasNanos(10); |
| 57 | + assertThat(DurationStyle.detectAndParse("-10ns")).hasNanos(-10); |
58 | 58 | } |
59 | 59 |
|
60 | 60 | @Test |
61 | 61 | void detectAndParseWhenSimpleMicrosShouldReturnDuration() { |
62 | | - assertThat(DurationStyle.detectAndParse("10us")).isEqualTo(Duration.ofNanos(10000)); |
63 | | - assertThat(DurationStyle.detectAndParse("10US")).isEqualTo(Duration.ofNanos(10000)); |
64 | | - assertThat(DurationStyle.detectAndParse("+10us")).isEqualTo(Duration.ofNanos(10000)); |
65 | | - assertThat(DurationStyle.detectAndParse("-10us")).isEqualTo(Duration.ofNanos(-10000)); |
| 62 | + assertThat(DurationStyle.detectAndParse("10us")).hasNanos(10000); |
| 63 | + assertThat(DurationStyle.detectAndParse("10US")).hasNanos(10000); |
| 64 | + assertThat(DurationStyle.detectAndParse("+10us")).hasNanos(10000); |
| 65 | + assertThat(DurationStyle.detectAndParse("-10us")).hasNanos(-10000); |
66 | 66 | } |
67 | 67 |
|
68 | 68 | @Test |
69 | 69 | void detectAndParseWhenSimpleMillisShouldReturnDuration() { |
70 | | - assertThat(DurationStyle.detectAndParse("10ms")).isEqualTo(Duration.ofMillis(10)); |
71 | | - assertThat(DurationStyle.detectAndParse("10MS")).isEqualTo(Duration.ofMillis(10)); |
72 | | - assertThat(DurationStyle.detectAndParse("+10ms")).isEqualTo(Duration.ofMillis(10)); |
73 | | - assertThat(DurationStyle.detectAndParse("-10ms")).isEqualTo(Duration.ofMillis(-10)); |
| 70 | + assertThat(DurationStyle.detectAndParse("10ms")).hasMillis(10); |
| 71 | + assertThat(DurationStyle.detectAndParse("10MS")).hasMillis(10); |
| 72 | + assertThat(DurationStyle.detectAndParse("+10ms")).hasMillis(10); |
| 73 | + assertThat(DurationStyle.detectAndParse("-10ms")).hasMillis(-10); |
74 | 74 | } |
75 | 75 |
|
76 | 76 | @Test |
77 | 77 | void detectAndParseWhenSimpleSecondsShouldReturnDuration() { |
78 | | - assertThat(DurationStyle.detectAndParse("10s")).isEqualTo(Duration.ofSeconds(10)); |
79 | | - assertThat(DurationStyle.detectAndParse("10S")).isEqualTo(Duration.ofSeconds(10)); |
80 | | - assertThat(DurationStyle.detectAndParse("+10s")).isEqualTo(Duration.ofSeconds(10)); |
81 | | - assertThat(DurationStyle.detectAndParse("-10s")).isEqualTo(Duration.ofSeconds(-10)); |
| 78 | + assertThat(DurationStyle.detectAndParse("10s")).hasSeconds(10); |
| 79 | + assertThat(DurationStyle.detectAndParse("10S")).hasSeconds(10); |
| 80 | + assertThat(DurationStyle.detectAndParse("+10s")).hasSeconds(10); |
| 81 | + assertThat(DurationStyle.detectAndParse("-10s")).hasSeconds(-10); |
82 | 82 | } |
83 | 83 |
|
84 | 84 | @Test |
85 | 85 | void detectAndParseWhenSimpleMinutesShouldReturnDuration() { |
86 | | - assertThat(DurationStyle.detectAndParse("10m")).isEqualTo(Duration.ofMinutes(10)); |
87 | | - assertThat(DurationStyle.detectAndParse("10M")).isEqualTo(Duration.ofMinutes(10)); |
88 | | - assertThat(DurationStyle.detectAndParse("+10m")).isEqualTo(Duration.ofMinutes(10)); |
89 | | - assertThat(DurationStyle.detectAndParse("-10m")).isEqualTo(Duration.ofMinutes(-10)); |
| 86 | + assertThat(DurationStyle.detectAndParse("10m")).hasMinutes(10); |
| 87 | + assertThat(DurationStyle.detectAndParse("10M")).hasMinutes(10); |
| 88 | + assertThat(DurationStyle.detectAndParse("+10m")).hasMinutes(10); |
| 89 | + assertThat(DurationStyle.detectAndParse("-10m")).hasMinutes(-10); |
90 | 90 | } |
91 | 91 |
|
92 | 92 | @Test |
93 | 93 | void detectAndParseWhenSimpleHoursShouldReturnDuration() { |
94 | | - assertThat(DurationStyle.detectAndParse("10h")).isEqualTo(Duration.ofHours(10)); |
95 | | - assertThat(DurationStyle.detectAndParse("10H")).isEqualTo(Duration.ofHours(10)); |
96 | | - assertThat(DurationStyle.detectAndParse("+10h")).isEqualTo(Duration.ofHours(10)); |
97 | | - assertThat(DurationStyle.detectAndParse("-10h")).isEqualTo(Duration.ofHours(-10)); |
| 94 | + assertThat(DurationStyle.detectAndParse("10h")).hasHours(10); |
| 95 | + assertThat(DurationStyle.detectAndParse("10H")).hasHours(10); |
| 96 | + assertThat(DurationStyle.detectAndParse("+10h")).hasHours(10); |
| 97 | + assertThat(DurationStyle.detectAndParse("-10h")).hasHours(-10); |
98 | 98 | } |
99 | 99 |
|
100 | 100 | @Test |
101 | 101 | void detectAndParseWhenSimpleDaysShouldReturnDuration() { |
102 | | - assertThat(DurationStyle.detectAndParse("10d")).isEqualTo(Duration.ofDays(10)); |
103 | | - assertThat(DurationStyle.detectAndParse("10D")).isEqualTo(Duration.ofDays(10)); |
104 | | - assertThat(DurationStyle.detectAndParse("+10d")).isEqualTo(Duration.ofDays(10)); |
105 | | - assertThat(DurationStyle.detectAndParse("-10d")).isEqualTo(Duration.ofDays(-10)); |
| 102 | + assertThat(DurationStyle.detectAndParse("10d")).hasDays(10); |
| 103 | + assertThat(DurationStyle.detectAndParse("10D")).hasDays(10); |
| 104 | + assertThat(DurationStyle.detectAndParse("+10d")).hasDays(10); |
| 105 | + assertThat(DurationStyle.detectAndParse("-10d")).hasDays(-10); |
106 | 106 | } |
107 | 107 |
|
108 | 108 | @Test |
109 | 109 | void detectAndParseWhenSimpleWithoutSuffixShouldReturnDuration() { |
110 | | - assertThat(DurationStyle.detectAndParse("10")).isEqualTo(Duration.ofMillis(10)); |
111 | | - assertThat(DurationStyle.detectAndParse("+10")).isEqualTo(Duration.ofMillis(10)); |
112 | | - assertThat(DurationStyle.detectAndParse("-10")).isEqualTo(Duration.ofMillis(-10)); |
| 110 | + assertThat(DurationStyle.detectAndParse("10")).hasMillis(10); |
| 111 | + assertThat(DurationStyle.detectAndParse("+10")).hasMillis(10); |
| 112 | + assertThat(DurationStyle.detectAndParse("-10")).hasMillis(-10); |
113 | 113 | } |
114 | 114 |
|
115 | 115 | @Test |
116 | 116 | void detectAndParseWhenSimpleWithoutSuffixButWithChronoUnitShouldReturnDuration() { |
117 | | - assertThat(DurationStyle.detectAndParse("10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); |
118 | | - assertThat(DurationStyle.detectAndParse("+10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); |
119 | | - assertThat(DurationStyle.detectAndParse("-10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(-10)); |
| 117 | + assertThat(DurationStyle.detectAndParse("10", ChronoUnit.SECONDS)).hasSeconds(10); |
| 118 | + assertThat(DurationStyle.detectAndParse("+10", ChronoUnit.SECONDS)).hasSeconds(10); |
| 119 | + assertThat(DurationStyle.detectAndParse("-10", ChronoUnit.SECONDS)).hasSeconds(-10); |
120 | 120 | } |
121 | 121 |
|
122 | 122 | @Test |
@@ -191,13 +191,13 @@ void parseIso8601WhenSimpleShouldThrowException() { |
191 | 191 |
|
192 | 192 | @Test |
193 | 193 | void parseSimpleShouldParse() { |
194 | | - assertThat(DurationStyle.SIMPLE.parse("10m")).isEqualTo(Duration.ofMinutes(10)); |
| 194 | + assertThat(DurationStyle.SIMPLE.parse("10m")).hasMinutes(10); |
195 | 195 | } |
196 | 196 |
|
197 | 197 | @Test |
198 | 198 | void parseSimpleWithUnitShouldUseUnitAsFallback() { |
199 | | - assertThat(DurationStyle.SIMPLE.parse("10m", ChronoUnit.SECONDS)).isEqualTo(Duration.ofMinutes(10)); |
200 | | - assertThat(DurationStyle.SIMPLE.parse("10", ChronoUnit.MINUTES)).isEqualTo(Duration.ofMinutes(10)); |
| 199 | + assertThat(DurationStyle.SIMPLE.parse("10m", ChronoUnit.SECONDS)).hasMinutes(10); |
| 200 | + assertThat(DurationStyle.SIMPLE.parse("10", ChronoUnit.MINUTES)).hasMinutes(10); |
201 | 201 | } |
202 | 202 |
|
203 | 203 | @Test |
|
0 commit comments