Skip to content

Commit e20df78

Browse files
committed
Make 'default' timezone deterministic in ConverterTest
Also add `@Test` annotation to `testLineLocalPortConverter` method, which looks like it was accidentally omitted. Signed-off-by: Richard North <[email protected]>
1 parent d4cce75 commit e20df78

File tree

1 file changed

+16
-2
lines changed
  • logback-access-common-blackbox/src/test/java/ch/qos/logback/access/common/blackbox/pattern

1 file changed

+16
-2
lines changed

logback-access-common-blackbox/src/test/java/ch/qos/logback/access/common/blackbox/pattern/ConverterTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.ArrayList;
4545
import java.util.List;
4646
import java.util.Locale;
47+
import java.util.TimeZone;
4748

4849
import static org.junit.jupiter.api.Assertions.assertEquals;
4950
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -79,8 +80,20 @@ public void testContentLengthConverter() {
7980
}
8081

8182
@Test
82-
public void testDateConverter() {
83-
dateConverterChecker(parseDateAsMillis("2024-08-14T15:29:25.956Z"), List.of(), "14/.../2024:17:29:25 \\+\\d*");
83+
public void testDateConverterWithDefaultTimezone() {
84+
TimeZone originalTimeZone = TimeZone.getDefault();
85+
try {
86+
// Set a known timezone for deterministic testing
87+
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
88+
dateConverterChecker(parseDateAsMillis("2024-08-14T15:29:25.956Z"), List.of(), "14/.../2024:17:29:25 \\+\\d*");
89+
} finally {
90+
// Restore original timezone
91+
TimeZone.setDefault(originalTimeZone);
92+
}
93+
}
94+
95+
@Test
96+
public void testDateConverterWithExplicitTimezone() {
8497
dateConverterChecker(parseDateAsMillis("2022-10-21T10:30:20.800Z"), List.of(CoreConstants.CLF_DATE_PATTERN, "Australia/Sydney", "en-AU"),
8598
"21/Oct/2022:21:30:20 \\+1100");
8699
dateConverterChecker(parseDateAsMillis("2022-09-21T10:30:20.800Z"), List.of(CoreConstants.CLF_DATE_PATTERN, "UTC", "en"),
@@ -111,6 +124,7 @@ void dateConverterChecker(long millis, List<String> options, String regex) {
111124
assertTrue(result.matches(regex));
112125
}
113126

127+
@Test
114128
public void testLineLocalPortConverter() {
115129
LocalPortConverter converter = new LocalPortConverter();
116130
converter.start();

0 commit comments

Comments
 (0)