Reputation: 271
I want to refactor exisiting code
String a = "Hi";
assertEquals(a, "Hi");
to
String a = "Hi";
assertEquals("Hi", a);
I have like 2 million assert statements all over my project that need to be refactored. Are they any shortcuts keys, templates or batch process in Eclipse IDE which I can implement to do this more easily?
assertEquals(expected, actual);
Upvotes: 2
Views: 179
Reputation: 3638
Having played a bit with the regex, I came up with the following solution (thanks to this link):
assertEquals\((.*), (.*)\);
captures the first and the second argument into a separate group 1 and group 2 respectively and should be pasted into the find
input field.
assertEquals($2, $1);
This command will swap the groups which were stored in $1 for the first and $2 for the second argument respectively.
WARNING
I am using Intellij IDEA for developing, thus it can come to an unexpected behaviour in eclipse. But the command should be almost the same ones.
Upvotes: 1
Reputation: 646
You could try the following:
org.junit.Assert.assertEquals
methods into a new class, let's say temp.TempAssert
import static org.junit.Assert.assertEquals;
with import static temp.TempAssert.assertEquals;
in all filesTempAssert
class and do Refactor -> Change Method Signature to switch order of parametersimport static temp.TempAssert.assertEquals;
back to import static org.junit.Assert.assertEquals;
in all filesUpvotes: 2