Skip to content

Commit

Permalink
Make ABI change mutators more robust
Browse files Browse the repository at this point in the history
We add a reference to the newly added method into one
of the existing methods. This would fail if the existing
method was static, because our newly added method was an
instance method. Fixed by making that method static too.
  • Loading branch information
oehme committed Jul 4, 2018
1 parent ce3cf1d commit f7bb981
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ classes
/profile-out
/profile-out-*
/foobar
/gradle-user-home
/gradle-user-home
/out
.DS_STORE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ protected void applyChangeTo(CompilationUnit compilationUnit) {
MethodDeclaration existingMethod = methods.get(0);
existingMethod.getBody().get().addStatement(0, new MethodCallExpr(null, newMethodName));

type.addMethod(newMethodName, Modifier.PUBLIC);
type.addMethod(newMethodName, Modifier.PUBLIC, Modifier.STATIC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class ApplyAbiChangeToJavaSourceFileMutatorTest extends Specification {
mutator.beforeBuild()

then:
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_1();}public void _m_1234_1() { }}")
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_1();}public static void _m_1234_1() { }}")

when:
mutator.beforeBuild()

then:
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_2();}public void _m_1234_2() { }}")
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_2();}public static void _m_1234_2() { }}")

when:
mutator.beforeBuild()

then:
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_3();}public void _m_1234_3() { }}")
parse(sourceFile) == parse("class Thing { public void existingMethod() { _m_1234_3();}public static void _m_1234_3() { }}")
}

def "reverts changes when nothing has been applied"() {
Expand Down

0 comments on commit f7bb981

Please sign in to comment.