Skip to content

Commit

Permalink
starting refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nahsra committed Aug 29, 2023
1 parent f4db05e commit 560c979
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ default void it_verifies_codemod(@TempDir final Path tmpDir) throws IOException
verifyCodemod(codemod, tmpDir, testDir, dependencies);
}

/**
* A hook for verifying the before and after files. By default, this method will compare the
* contents of the two files for exact equality.
*
* @param expected the file contents that are expected after transformation
* @param after a file containing the contents after transformation
*/
default void verifyTransformedCode(final Path expected, final Path after) throws IOException {
String expectedCode = Files.readString(expected);
String transformedJavaCode = Files.readString(after);
assertThat(transformedJavaCode, equalTo(expectedCode));
}

private void verifyCodemod(
final Class<? extends CodeChanger> codemodType,
final Path tmpDir,
Expand Down Expand Up @@ -86,9 +99,8 @@ private void verifyCodemod(
assertThat(result.getFailedFiles().size(), equalTo(0));

// make sure the file is transformed to the expected output
String expectedCode = Files.readString(after);
String transformedJavaCode = Files.readString(pathToJavaFile);
assertThat(transformedJavaCode, equalTo(expectedCode));
verifyTransformedCode(after, pathToJavaFile);

assertThat(changeset.size(), is(1));
CodeTFChangesetEntry entry = changeset.get(0);
assertThat(entry.getChanges().isEmpty(), is(false));
Expand Down Expand Up @@ -117,6 +129,7 @@ private void verifyCodemod(
List<CodeTFChangesetEntry> changeset2 = result2.getChangeset();
assertThat(changeset2.size(), is(0));
String transformedAgainJavaCode = Files.readString(pathToJavaFile);
String expectedCode = Files.readString(after);
assertThat(transformedAgainJavaCode, equalTo(expectedCode));
}
}

0 comments on commit 560c979

Please sign in to comment.