-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create shared utility for verifying fix locations (#358)
The different codemod test mixins need to start being brought together, and this is a small step towards that. --------- Co-authored-by: Carlos Uscanga <[email protected]>
- Loading branch information
Showing
5 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
framework/codemodder-testutils/src/main/java/io/codemodder/testutils/ExpectedFixes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.codemodder.testutils; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import io.codemodder.CodeChanger; | ||
import io.codemodder.FixOnlyCodeChanger; | ||
import io.codemodder.codetf.CodeTFChange; | ||
import io.codemodder.codetf.CodeTFChangesetEntry; | ||
import io.codemodder.codetf.CodeTFResult; | ||
import io.codemodder.codetf.UnfixedFinding; | ||
import java.util.List; | ||
|
||
/** Utilities for verifying expected fixes. */ | ||
final class ExpectedFixes { | ||
|
||
private ExpectedFixes() {} | ||
|
||
/** Verify the expected fix metadata. */ | ||
static void verifyExpectedFixes( | ||
final CodeTFResult result, | ||
final CodeChanger changer, | ||
final int[] expectedFixLines, | ||
final int[] expectingFailedFixesAtLines) { | ||
List<CodeTFChange> changes = | ||
result.getChangeset().stream() | ||
.map(CodeTFChangesetEntry::getChanges) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
if (changer instanceof FixOnlyCodeChanger) { | ||
assertThat(changes.stream().anyMatch(c -> !c.getFixedFindings().isEmpty()), is(true)); | ||
} | ||
|
||
for (int expectedFixLine : expectedFixLines) { | ||
assertThat(changes.stream().anyMatch(c -> c.getLineNumber() == expectedFixLine), is(true)); | ||
} | ||
|
||
List<UnfixedFinding> unfixedFindings = result.getUnfixedFindings(); | ||
for (int expectedFailedFixLine : expectingFailedFixesAtLines) { | ||
assertThat( | ||
unfixedFindings.stream().noneMatch(c -> c.getLine() == expectedFailedFixLine), is(true)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters