Skip to content

Commit c45130b

Browse files
test: improve coverage for TestMethodDiviner classes
**What:** Added unit tests covering the `index == -1` (no match) edge cases in `TestMethodDivinerNoPraefixTest` and `TestMethodDivinerJunit3PraefixTest`. **Why:** The previous refactoring from `replaceFirst` to `indexOf` introduced a new `if (index != -1)` branch which was not covered by existing tests, causing the Codecov CI check to fail due to a drop in diff coverage. **Impact:** Increases code coverage and ensures that renaming methods correctly fallback when the expected prefix/suffix string does not exist in the target string. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent 726caf9 commit c45130b

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

.jules/bolt.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
## 2026-05-22 - Replacing literal `replaceFirst` with manual string searches
3131
**Learning:** Using regex-based `replaceFirst` for literal search-and-replace, especially when dealing with prefixes or static replacements, is computationally expensive due to the overhead of `Pattern` compilation and matching. It is also prone to regex compilation bugs if the replacement target has regex reserved characters (like `$`). Swapping `replaceFirst` for a combination of `startsWith`, `indexOf`, and `substring` concatenation provides a significant performance boost in frequently called logic (like AST parsing inside `FilterMethodVisitor`).
3232
**Action:** When finding exact substring replacements or prefix removal, manually calculate indices and substring lengths using `indexOf`/`substring` instead of `replaceFirst`.
33+
## 2026-05-22 - Code Coverage Failures after refactoring regex
34+
**Learning:** When refactoring regex paths (like `replaceFirst`) into equivalent literal matches (`startsWith`, `indexOf`, `substring`), new specific edge-case branches (like `if (index != -1)`) might not have existing unit test coverage. This will trigger Codecov PR failures because the overall diff coverage drops below the required threshold.
35+
**Action:** When making logical refactorings, proactively add unit tests for the new conditional branches introduced by the refactoring, even if they seem trivial, to ensure CI coverage checks pass.

org.moreunit.test/test/org/moreunit/util/TestMethodDivinerJunit3PraefixTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,11 @@ public void getTestMethodNameAfterRename()
5656
assertThat(testMethodDiviner.getTestMethodNameAfterRename("countMembers", "countAllMembers", "testCountMembersSpecialCase")).isEqualTo("testCountAllMembersSpecialCase");
5757
assertThat(testMethodDiviner.getTestMethodNameAfterRename("countMembers", "countAllMembers", "testCountMembers")).isEqualTo("testCountAllMembers");
5858
}
59+
60+
@Test
61+
public void getTestMethodNameAfterRename_noMatch()
62+
{
63+
TestMethodDiviner testMethodDiviner = new TestMethodDivinerJunit3Praefix();
64+
assertThat(testMethodDiviner.getTestMethodNameAfterRename("countMembers", "countAllMembers", "testSomethingElse")).isEqualTo("testSomethingElse");
65+
}
5966
}

org.moreunit.test/test/org/moreunit/util/TestMethodDivinerNoPraefixTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public void testGetTestMethodNameAfterRename() throws Exception
2121
assertThat(testMethodDivinerNoPraefix.getTestMethodNameAfterRename("getFoo", "get2Foo", "getFoo_getterWorks")).isEqualTo("get2Foo_getterWorks");
2222
}
2323

24+
@Test
25+
public void testGetTestMethodNameAfterRename_noMatch() throws Exception
26+
{
27+
TestMethodDivinerNoPraefix testMethodDivinerNoPraefix = new TestMethodDivinerNoPraefix();
28+
assertThat(testMethodDivinerNoPraefix.getTestMethodNameAfterRename("getFoo", "get2Foo", "somethingElse")).isEqualTo("somethingElse");
29+
}
30+
2431
@Test
2532
public void getMethodNameFromTestMethodName() throws Exception
2633
{

test_diviner.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# check line numbers for missing coverage

0 commit comments

Comments
 (0)