make date axis formatter tests locale-stable
What changed, and why it matters
This commit only changes a test file to make date-formatting unit tests stable across different computer locales. It does not modify the actual wallet application code, so it has no security impact on users.
No security action needed; treat as a normal test-maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch updates DateAxisFormatterTest.java to avoid hardcoded locale-dependent expectations (e.g., English month names, ‘d MMM’, ‘HH:mm’) by deriving expected strings from SimpleDateFormat in the default locale. This is a test-only reliability fix; no production code is altered.
Changed components
src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.javaInspect captured patch +13 / −11
diff --git a/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java b/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java
index 812c8d7..e73c648 100644
--- a/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java
+++ b/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java
@@ -3,7 +3,9 @@ package com.sparrowwallet.sparrow.control;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
@@ -28,27 +30,27 @@ public class DateAxisFormatterTest {
@Test
public void multiYearDurationIncludesFourDigitYear() {
DateAxisFormatter formatter = new DateAxisFormatter(2 * YEAR);
- String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
- Assertions.assertTrue(label.matches("\\p{L}+ \\d{4}"),
- "Expected month + 4-digit year, got: " + label);
- Assertions.assertTrue(label.endsWith("2024"),
- "Expected year 2024 in label, got: " + label);
+ long ts = timestamp(2024, Calendar.AUGUST, 15);
+ String actual = thirdLabel(formatter, ts);
+ String fourDigitYear = new SimpleDateFormat("yyyy").format(new Date(ts));
+ Assertions.assertTrue(actual.contains(fourDigitYear),
+ "Expected 4-digit year " + fourDigitYear + " in label, got: " + actual);
}
@Test
public void subYearDurationUsesDayMonth() {
DateAxisFormatter formatter = new DateAxisFormatter(30 * DAY);
- String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
- Assertions.assertTrue(label.matches("\\d{1,2} \\p{L}+"),
- "Expected day + month, got: " + label);
+ long ts = timestamp(2024, Calendar.AUGUST, 15);
+ Assertions.assertEquals(new SimpleDateFormat("d MMM").format(new Date(ts)),
+ thirdLabel(formatter, ts));
}
@Test
public void subDayDurationUsesHourMinute() {
DateAxisFormatter formatter = new DateAxisFormatter(2 * HOUR);
- String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
- Assertions.assertTrue(label.matches("\\d{2}:\\d{2}"),
- "Expected HH:mm, got: " + label);
+ long ts = timestamp(2024, Calendar.AUGUST, 15);
+ Assertions.assertEquals(new SimpleDateFormat("HH:mm").format(new Date(ts)),
+ thirdLabel(formatter, ts));
}
@Test
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.