|
24 | 24 | import java.time.Instant; |
25 | 25 | import java.time.temporal.Temporal; |
26 | 26 | import java.time.temporal.TemporalAccessor; |
| 27 | +import java.time.temporal.TemporalAmount; |
27 | 28 | import java.time.temporal.TemporalField; |
28 | 29 | import java.time.temporal.TemporalUnit; |
29 | 30 | import java.util.Arrays; |
| 31 | +import java.util.List; |
30 | 32 |
|
31 | 33 | import org.apache.commons.lang3.AbstractLangTest; |
32 | 34 | import org.junit.jupiter.api.Test; |
@@ -78,16 +80,18 @@ static class MyClass { |
78 | 80 | private final MyCharSequence charSequence; |
79 | 81 | private final MyTemporal temporal; |
80 | 82 | private final MyTemporalAccessor temporalAccessor; |
| 83 | + private final MyTemporalAmount temporalAmount; |
81 | 84 |
|
82 | | - MyClass(final MyTemporal temporal, final MyTemporalAccessor temporalAccessor, final MyCharSequence charSequence) { |
| 85 | + MyClass(final MyCharSequence charSequence, final MyTemporal temporal, final MyTemporalAccessor temporalAccessor, final MyTemporalAmount temporalAmount) { |
83 | 86 | this.charSequence = charSequence; |
84 | 87 | this.temporal = temporal; |
85 | 88 | this.temporalAccessor = temporalAccessor; |
| 89 | + this.temporalAmount = temporalAmount; |
86 | 90 | } |
87 | 91 |
|
88 | 92 | @Override |
89 | 93 | public String toString() { |
90 | | - return String.format("%s[%s - %s - %s]", getClass().getSimpleName(), charSequence, temporal, temporalAccessor); |
| 94 | + return String.format("%s[%s - %s - %s - $s]", getClass().getSimpleName(), charSequence, temporal, temporalAccessor, temporalAmount); |
91 | 95 | } |
92 | 96 | } |
93 | 97 |
|
@@ -141,7 +145,6 @@ public Temporal with(final TemporalField field, final long newValue) { |
141 | 145 | } |
142 | 146 |
|
143 | 147 | } |
144 | | - |
145 | 148 | static class MyTemporalAccessor implements TemporalAccessor { |
146 | 149 |
|
147 | 150 | private final String string; |
@@ -173,13 +176,55 @@ public String toString() { |
173 | 176 |
|
174 | 177 | } |
175 | 178 |
|
| 179 | + static class MyTemporalAmount implements TemporalAmount { |
| 180 | + |
| 181 | + private final String string; |
| 182 | + private final long value; |
| 183 | + private final Instant instant; |
| 184 | + private final Duration duration; |
| 185 | + |
| 186 | + MyTemporalAmount(final String string) { |
| 187 | + this.string = string; |
| 188 | + this.value = Long.parseLong(string); |
| 189 | + this.instant = Instant.ofEpochMilli(value); |
| 190 | + this.duration = Duration.between(instant, instant.plusMillis(value)); |
| 191 | + } |
| 192 | + |
| 193 | + @Override |
| 194 | + public Temporal addTo(final Temporal temporal) { |
| 195 | + return null; |
| 196 | + } |
| 197 | + |
| 198 | + @Override |
| 199 | + public long get(final TemporalUnit unit) { |
| 200 | + return 0; |
| 201 | + } |
| 202 | + |
| 203 | + @Override |
| 204 | + public List<TemporalUnit> getUnits() { |
| 205 | + return null; |
| 206 | + } |
| 207 | + |
| 208 | + @Override |
| 209 | + public Temporal subtractFrom(final Temporal temporal) { |
| 210 | + return null; |
| 211 | + } |
| 212 | + |
| 213 | + @Override |
| 214 | + public String toString() { |
| 215 | + return String.format("%s[%s - %s - %s]", getClass().getSimpleName(), string, instant, duration); |
| 216 | + } |
| 217 | + |
| 218 | + |
| 219 | + } |
| 220 | + |
176 | 221 | @Test |
177 | 222 | public void testRecursive() { |
178 | | - final MyClass o1 = new MyClass(new MyTemporal("1"), new MyTemporalAccessor("2"), new MyCharSequence("3")); |
| 223 | + final MyClass o1 = new MyClass(new MyCharSequence("1"), new MyTemporal("2"), new MyTemporalAccessor("3"), new MyTemporalAmount("4")); |
179 | 224 | // This gives you different instances of MyTemporalAccessor for 1 (and 2) that should be equals by reflection. |
180 | | - final MyClass o1Bis = new MyClass(new MyTemporal("1"), new MyTemporalAccessor("2"), new MyCharSequence("3")); |
181 | | - final MyClass o2 = new MyClass(new MyTemporal("4"), new MyTemporalAccessor("5"), new MyCharSequence("6")); |
182 | | - final MyClass o2Bis = new MyClass(new MyTemporal("4"), new MyTemporalAccessor("5"), new MyCharSequence("6")); |
| 225 | + final MyClass o1Bis = new MyClass(new MyCharSequence("1"), new MyTemporal("2"), new MyTemporalAccessor("3"), new MyTemporalAmount("4")); |
| 226 | + final MyClass o2 = new MyClass(new MyCharSequence("5"), new MyTemporal("6"), new MyTemporalAccessor("7"), new MyTemporalAmount("8")); |
| 227 | + final MyClass o2Bis = new MyClass(new MyCharSequence("5"), new MyTemporal("6"), new MyTemporalAccessor("7"), new MyTemporalAmount("8")); |
183 | 228 | // MyTemporal |
184 | 229 | assertTrue(new EqualsBuilder().setTestRecursive(true).append(new MyTemporal("1"), new MyTemporal("1")).isEquals()); |
185 | 230 | // MyTemporalAccessor |
|
0 commit comments