Skip to content

Commit a87a261

Browse files
committed
Update EqualsBuilderReflectJreImplementationTest for built-in dates and
times
1 parent 8034ce7 commit a87a261

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
<properties>
469469
<!-- LANG-1265: allow tests to access private fields/methods of java.base classes via reflection -->
470470
<!-- LANG-1667: allow tests to access private fields/methods of java.base/java.util such as ArrayList via reflection -->
471-
<argLine>-Xmx512m --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED</argLine>
471+
<argLine>-Xmx512m --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED --add-opens java.base/java.time.chrono=ALL-UNNAMED</argLine>
472472
</properties>
473473
</profile>
474474
<profile>

src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationTest.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@
2222

2323
import java.time.Duration;
2424
import java.time.Instant;
25+
import java.time.LocalDate;
26+
import java.time.LocalDateTime;
27+
import java.time.LocalTime;
28+
import java.time.OffsetDateTime;
29+
import java.time.OffsetTime;
2530
import java.time.Period;
31+
import java.time.Year;
32+
import java.time.YearMonth;
33+
import java.time.ZoneId;
34+
import java.time.ZoneOffset;
35+
import java.time.ZonedDateTime;
36+
import java.time.chrono.HijrahDate;
37+
import java.time.chrono.JapaneseDate;
38+
import java.time.chrono.MinguoDate;
39+
import java.time.chrono.ThaiBuddhistDate;
2640
import java.time.temporal.Temporal;
2741
import java.time.temporal.TemporalAccessor;
2842
import java.time.temporal.TemporalAmount;
@@ -82,17 +96,33 @@ static class MyClass {
8296
private final MyTemporal temporal;
8397
private final MyTemporalAccessor temporalAccessor;
8498
private final MyTemporalAmount temporalAmount;
99+
private final Object[] objects;
85100

86-
MyClass(final MyCharSequence charSequence, final MyTemporal temporal, final MyTemporalAccessor temporalAccessor, final MyTemporalAmount temporalAmount) {
101+
MyClass(final MyCharSequence charSequence, final MyTemporal temporal, final MyTemporalAccessor temporalAccessor,
102+
final MyTemporalAmount temporalAmount) {
87103
this.charSequence = charSequence;
88104
this.temporal = temporal;
89105
this.temporalAccessor = temporalAccessor;
90106
this.temporalAmount = temporalAmount;
107+
final int value = Integer.parseInt(charSequence.toString());
108+
final LocalDate localDate = LocalDate.ofEpochDay(value);
109+
final LocalTime localTime = LocalTime.of(value, value);
110+
final LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
111+
final OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, ZoneOffset.UTC);
112+
final ZoneOffset zoneOffset = ZoneOffset.ofHours(value);
113+
this.objects = new Object[] {
114+
// a Long
115+
value,
116+
// all concrete dates and times
117+
localDate, HijrahDate.from(localDate), JapaneseDate.from(localDate), MinguoDate.from(localDate), ThaiBuddhistDate.from(localDate),
118+
localDate, localTime, localDateTime, offsetDateTime, OffsetTime.of(localTime, zoneOffset), Year.of(value), YearMonth.of(value, value),
119+
ZonedDateTime.of(localDateTime, zoneOffset), zoneOffset, ZoneId.of(zoneOffset.getId()) };
91120
}
92121

93122
@Override
94123
public String toString() {
95-
return String.format("%s[%s - %s - %s - $s]", getClass().getSimpleName(), charSequence, temporal, temporalAccessor, temporalAmount);
124+
return String.format("%s[%s, %s, %s, %s, %s]", getClass().getSimpleName(), charSequence, temporal, temporalAccessor, temporalAmount,
125+
Arrays.toString(objects));
96126
}
97127
}
98128

@@ -114,37 +144,37 @@ static class MyTemporal implements Temporal {
114144

115145
@Override
116146
public long getLong(final TemporalField field) {
117-
return 0;
147+
return instant.get(field);
118148
}
119149

120150
@Override
121151
public boolean isSupported(final TemporalField field) {
122-
return false;
152+
return instant.isSupported(field);
123153
}
124154

125155
@Override
126156
public boolean isSupported(final TemporalUnit unit) {
127-
return false;
157+
return instant.isSupported(unit);
128158
}
129159

130160
@Override
131161
public Temporal plus(final long amountToAdd, final TemporalUnit unit) {
132-
return null;
162+
return instant.plus(amountToAdd, unit);
133163
}
134164

135165
@Override
136166
public String toString() {
137-
return String.format("%s[%s - %s - %s]", getClass().getSimpleName(), string, instant, duration, period);
167+
return String.format("%s[%s, %s, %s, %s]", getClass().getSimpleName(), string, instant, duration, period);
138168
}
139169

140170
@Override
141171
public long until(final Temporal endExclusive, final TemporalUnit unit) {
142-
return 0;
172+
return instant.until(endExclusive, unit);
143173
}
144174

145175
@Override
146176
public Temporal with(final TemporalField field, final long newValue) {
147-
return null;
177+
return instant.with(field, newValue);
148178
}
149179

150180
}
@@ -162,22 +192,21 @@ static class MyTemporalAccessor implements TemporalAccessor {
162192
this.instant = Instant.ofEpochMilli(value);
163193
this.duration = Duration.between(instant, instant.plusMillis(value));
164194
this.period = Period.ofDays(value);
165-
166195
}
167196

168197
@Override
169198
public long getLong(final TemporalField field) {
170-
return 0;
199+
return instant.get(field);
171200
}
172201

173202
@Override
174203
public boolean isSupported(final TemporalField field) {
175-
return false;
204+
return instant.isSupported(field);
176205
}
177206

178207
@Override
179208
public String toString() {
180-
return String.format("%s[%s - %s - % - %s]", getClass().getSimpleName(), string, instant, duration, period);
209+
return String.format("%s[%s, %s, %s, %s]", getClass().getSimpleName(), string, instant, duration, period);
181210
}
182211

183212
}
@@ -200,22 +229,22 @@ static class MyTemporalAmount implements TemporalAmount {
200229

201230
@Override
202231
public Temporal addTo(final Temporal temporal) {
203-
return null;
232+
return duration.addTo(temporal);
204233
}
205234

206235
@Override
207236
public long get(final TemporalUnit unit) {
208-
return 0;
237+
return duration.get(unit);
209238
}
210239

211240
@Override
212241
public List<TemporalUnit> getUnits() {
213-
return null;
242+
return duration.getUnits();
214243
}
215244

216245
@Override
217246
public Temporal subtractFrom(final Temporal temporal) {
218-
return null;
247+
return duration.subtractFrom(temporal);
219248
}
220249

221250
@Override

0 commit comments

Comments
 (0)