ramanathan1504 commented on code in PR #4400:
URL: https://github.com/apache/logging-log4j2/pull/4400#discussion_r4329770994
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatterTest.java:
##########
@@ -374,13 +375,35 @@ private static void assertPatternPrecision(final String
pattern, final ChronoUni
@MethodSource("formatterInputs")
void output_should_match_DateTimeFormatter(
final String pattern, final Locale locale, final TimeZone
timeZone, final MutableInstant instant) {
+ assertOutputMatchesDateTimeFormatter(pattern, locale, timeZone,
instant);
+ }
+
+ @ParameterizedTest
+ @MethodSource("formatterInputsBeforeTheEpoch")
+ void output_before_the_epoch_should_match_DateTimeFormatter(
+ final String pattern, final Locale locale, final TimeZone
timeZone, final MutableInstant instant) {
+ assertOutputMatchesDateTimeFormatter(pattern, locale, timeZone,
instant);
+ }
+
+ private static void assertOutputMatchesDateTimeFormatter(
+ final String pattern, final Locale locale, final TimeZone
timeZone, final MutableInstant instant) {
final String log4jOutput = formatInstant(pattern, locale, timeZone,
instant);
final String javaOutput = DateTimeFormatter.ofPattern(pattern, locale)
.withZone(timeZone.toZoneId())
.format(instant);
assertThat(log4jOutput).isEqualTo(javaOutput);
}
Review Comment:
One formatter for both instants, so the cached minute is reused. This fails
if `toEpochMinutes` goes back to `/ 60`. It needs `import
org.junit.jupiter.api.Test;`.
```suggestion
@Test
void reused_formatter_should_not_mix_minutes_around_the_epoch() {
final InstantPatternFormatter formatter =
new InstantPatternDynamicFormatter("HH:mm:ss", Locale.US,
TimeZone.getTimeZone("UTC"));
final MutableInstant afterTheEpoch = new MutableInstant();
afterTheEpoch.initFromEpochSecond(30, 0);
formatter.formatTo(new StringBuilder(), afterTheEpoch);
final MutableInstant beforeTheEpoch = new MutableInstant();
beforeTheEpoch.initFromEpochSecond(-30, 0);
final StringBuilder buffer = new StringBuilder();
formatter.formatTo(buffer, beforeTheEpoch);
assertThat(buffer).hasToString("23:59:30");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]