From f11f8c536ab2ff3abe8db727d0cd7e60d7a98b2d Mon Sep 17 00:00:00 2001 From: Gray Zhang Date: Thu, 18 Sep 2025 22:35:14 +0800 Subject: [PATCH 1/2] fix: correct parsing of consecutive sign-in days MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the extractDigits() method extracted all digits from the string, causing incorrect display when the string contained user IDs or dates. Now uses regex to specifically extract the number before "天" (days). This fixes the issue where sign-in days displayed incorrectly as "21612902025091812天" instead of the actual consecutive days count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../me/ghui/v2er/network/bean/DailyInfo.java | 16 +++++ .../ghui/v2er/network/bean/DailyInfoTest.java | 68 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java diff --git a/app/src/main/java/me/ghui/v2er/network/bean/DailyInfo.java b/app/src/main/java/me/ghui/v2er/network/bean/DailyInfo.java index 08cb66b6..b52552e7 100644 --- a/app/src/main/java/me/ghui/v2er/network/bean/DailyInfo.java +++ b/app/src/main/java/me/ghui/v2er/network/bean/DailyInfo.java @@ -26,6 +26,22 @@ public boolean hadCheckedIn() { } public String getCheckinDays() { + if (Check.isEmpty(continuousLoginDayStr)) return ""; + + // Extract consecutive days from strings like: + // "您已连续登录 123 天" + // "ghui 已连续签到 12 天 2024/12/25" + // "用户161290已连续签到 5 天" + + // Use regex to find number followed by "天" (days) + java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(\\d+)\\s*天"); + java.util.regex.Matcher matcher = pattern.matcher(continuousLoginDayStr); + + if (matcher.find()) { + return matcher.group(1); + } + + // Fallback to extracting all digits if pattern not found return Utils.extractDigits(continuousLoginDayStr); } diff --git a/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java b/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java new file mode 100644 index 00000000..66321b9e --- /dev/null +++ b/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java @@ -0,0 +1,68 @@ +package me.ghui.v2er.network.bean; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class DailyInfoTest { + + @Test + public void testGetCheckinDays_withValidFormat() { + // Test case 1: Standard format + DailyInfo dailyInfo = new DailyInfo(); + dailyInfo.continuousLoginDayStr = "您已连续登录 123 天"; + assertEquals("123", dailyInfo.getCheckinDays()); + } + + @Test + public void testGetCheckinDays_withDateInString() { + // Test case 2: String contains date and other numbers + DailyInfo dailyInfo = new DailyInfo(); + // Simulate the actual problematic string that might appear + dailyInfo.continuousLoginDayStr = "ghui 已连续签到 12 天 2024/12/25"; + String result = dailyInfo.getCheckinDays(); + // After fix, it should correctly extract "12" + assertEquals("12", result); + } + + @Test + public void testGetCheckinDays_withUserId() { + // Test case 3: String contains user ID and days + DailyInfo dailyInfo = new DailyInfo(); + dailyInfo.continuousLoginDayStr = "用户161290已连续签到 5 天"; + String result = dailyInfo.getCheckinDays(); + // After fix, it should correctly extract "5" + assertEquals("5", result); + } + + @Test + public void testGetCheckinDays_withNull() { + DailyInfo dailyInfo = new DailyInfo(); + dailyInfo.continuousLoginDayStr = null; + assertEquals("", dailyInfo.getCheckinDays()); + } + + @Test + public void testGetCheckinDays_withEmpty() { + DailyInfo dailyInfo = new DailyInfo(); + dailyInfo.continuousLoginDayStr = ""; + assertEquals("", dailyInfo.getCheckinDays()); + } + + // Make continuousLoginDayStr accessible for testing + private static class DailyInfo extends me.ghui.v2er.network.bean.DailyInfo { + String continuousLoginDayStr; + + @Override + public String getCheckinDays() { + // Use reflection or make the field package-private in actual implementation + try { + java.lang.reflect.Field field = me.ghui.v2er.network.bean.DailyInfo.class.getDeclaredField("continuousLoginDayStr"); + field.setAccessible(true); + field.set(this, continuousLoginDayStr); + } catch (Exception e) { + e.printStackTrace(); + } + return super.getCheckinDays(); + } + } +} \ No newline at end of file From 636dd73bad5baea23a096be185148bbe4c54dfca Mon Sep 17 00:00:00 2001 From: Gray Zhang Date: Thu, 18 Sep 2025 22:47:34 +0800 Subject: [PATCH 2/2] fix: improve test code based on Copilot suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use specific exception types instead of generic Exception - Throw RuntimeException instead of just printing stack trace to make test failures explicit - Improves test maintainability and failure debugging 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../test/java/me/ghui/v2er/network/bean/DailyInfoTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java b/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java index 66321b9e..de3f525e 100644 --- a/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java +++ b/app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java @@ -54,13 +54,14 @@ private static class DailyInfo extends me.ghui.v2er.network.bean.DailyInfo { @Override public String getCheckinDays() { - // Use reflection or make the field package-private in actual implementation + // Use reflection to set the field for testing purposes try { java.lang.reflect.Field field = me.ghui.v2er.network.bean.DailyInfo.class.getDeclaredField("continuousLoginDayStr"); field.setAccessible(true); field.set(this, continuousLoginDayStr); - } catch (Exception e) { - e.printStackTrace(); + } catch (NoSuchFieldException | IllegalAccessException e) { + // Fail the test explicitly if reflection fails + throw new RuntimeException("Failed to access continuousLoginDayStr via reflection: " + e.getMessage(), e); } return super.getCheckinDays(); }