Skip to content

Commit becfef0

Browse files
Rohitesh-Kumar-Jainwoutersmeenk
authored andcommitted
test: Migrate all refactoring tests to Junit5 (INRIA#4007)
1 parent 75c8bed commit becfef0

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

src/test/java/spoon/test/refactoring/CtRenameGenericVariableRefactoringTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
package spoon.test.refactoring;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020
import spoon.Launcher;
2121
import spoon.refactoring.CtRenameGenericVariableRefactoring;
2222
import spoon.reflect.code.CtLocalVariable;
2323
import spoon.reflect.declaration.*;
2424

25-
import static org.junit.Assert.assertNotEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2626

2727
public class CtRenameGenericVariableRefactoringTest
2828
{

src/test/java/spoon/test/refactoring/CtRenameLocalVariableRefactoringTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package spoon.test.refactoring;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020
import spoon.Launcher;
2121
import spoon.OutputType;
2222
import spoon.SpoonException;
@@ -42,8 +42,8 @@
4242
import java.net.URL;
4343
import java.net.URLClassLoader;
4444

45-
import static org.junit.Assert.assertEquals;
46-
import static org.junit.Assert.fail;
45+
import static org.junit.jupiter.api.Assertions.assertEquals;
46+
import static org.junit.jupiter.api.Assertions.fail;
4747

4848
public class CtRenameLocalVariableRefactoringTest
4949
{
@@ -125,15 +125,15 @@ private void checkLocalVariableRename(Launcher launcher, CtLocalVariable<?> targ
125125
} catch(SpoonException e) {
126126
throw new AssertionError(getParentMethodName(targetVariable)+" Rename of \""+originName+"\" should NOT fail when trying rename to \""+newName+"\"\n"+targetVariable.toString(), e);
127127
}
128-
assertEquals(getParentMethodName(targetVariable)+" Rename of \""+originName+"\" to \""+newName+"\" passed, but the name of variable was not changed", newName, targetVariable.getSimpleName());
128+
assertEquals(newName, targetVariable.getSimpleName(), getParentMethodName(targetVariable)+" Rename of \""+originName+"\" to \""+newName+"\" passed, but the name of variable was not changed");
129129
assertCorrectModel(launcher, getParentMethodName(targetVariable)+" Rename of \""+originName+"\" to \""+newName+"\"");
130130
} else {
131131
try {
132132
refactor.refactor();
133133
fail(getParentMethodName(targetVariable)+" Rename of \""+originName+"\" should fail when trying rename to \""+newName+"\"");
134134
} catch(SpoonException e) {
135135
}
136-
assertEquals(getParentMethodName(targetVariable)+" Rename of \""+originName+"\" failed when trying rename to \""+newName+"\" but the name of variable should not be changed", originName, targetVariable.getSimpleName());
136+
assertEquals(originName, targetVariable.getSimpleName(), getParentMethodName(targetVariable)+" Rename of \""+originName+"\" failed when trying rename to \""+newName+"\" but the name of variable should not be changed");
137137
}
138138
if(renameShouldPass) {
139139
rollback(targetVariable, originName);

src/test/java/spoon/test/refactoring/MethodsRefactoringTest.java

+25-25
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package spoon.test.refactoring;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020
import spoon.Launcher;
2121
import spoon.OutputType;
2222
import spoon.SpoonModelBuilder;
@@ -55,14 +55,14 @@
5555
import java.util.Iterator;
5656
import java.util.List;
5757

58-
import static org.junit.Assert.assertEquals;
59-
import static org.junit.Assert.assertFalse;
60-
import static org.junit.Assert.assertNotNull;
61-
import static org.junit.Assert.assertNotSame;
62-
import static org.junit.Assert.assertNull;
63-
import static org.junit.Assert.assertSame;
64-
import static org.junit.Assert.assertTrue;
65-
import static org.junit.Assert.fail;
58+
import static org.junit.jupiter.api.Assertions.assertEquals;
59+
import static org.junit.jupiter.api.Assertions.assertFalse;
60+
import static org.junit.jupiter.api.Assertions.assertNotNull;
61+
import static org.junit.jupiter.api.Assertions.assertNotSame;
62+
import static org.junit.jupiter.api.Assertions.assertNull;
63+
import static org.junit.jupiter.api.Assertions.assertSame;
64+
import static org.junit.jupiter.api.Assertions.assertTrue;
65+
import static org.junit.jupiter.api.Assertions.fail;
6666

6767
public class MethodsRefactoringTest {
6868

@@ -116,9 +116,9 @@ public void testSubInheritanceHierarchyFunction() {
116116

117117
private void checkContainsOnly(List<String> foundNames, String... expectedNames) {
118118
for (String name : expectedNames) {
119-
assertTrue("The "+name+" not found", foundNames.remove(name));
119+
assertTrue(foundNames.remove(name), "The "+name+" not found");
120120
}
121-
assertTrue("Unexpected names found: "+foundNames, foundNames.isEmpty());
121+
assertTrue(foundNames.isEmpty(), "Unexpected names found: "+foundNames);
122122
}
123123

124124
@Test
@@ -141,10 +141,10 @@ public void testAllMethodsSameSignatureFunction() {
141141
//contract: CtConstructor has no other same signature
142142
CtConstructor<?> constructorTypeA = factory.Class().get(TypeA.class).getConstructors().iterator().next();
143143
CtExecutable<?> exec = constructorTypeA.map(new AllMethodsSameSignatureFunction()).first();
144-
assertNull("Unexpected executable found by Constructor of TypeA "+exec, exec);
144+
assertNull(exec, "Unexpected executable found by Constructor of TypeA "+exec);
145145
CtConstructor<?> constructorTypeB = factory.Class().get(TypeB.class).getConstructors().iterator().next();
146146
exec = constructorTypeA.map(new AllMethodsSameSignatureFunction()).first();
147-
assertNull("Unexpected executable found by Constructor of TypeA "+exec, exec);
147+
assertNull(exec, "Unexpected executable found by Constructor of TypeA "+exec);
148148
//contract: constructor is returned if includingSelf == true
149149
assertSame(constructorTypeA, constructorTypeA.map(new AllMethodsSameSignatureFunction().includingSelf(true)).first());
150150
}
@@ -173,46 +173,46 @@ private void checkMethodHierarchy(List<CtExecutable<?>> expectedExecutables, CtE
173173
//contract: check that by default it returns lambdas
174174
{
175175
final List<CtExecutable<?>> executables = startExecutable.map(new AllMethodsSameSignatureFunction()).list();
176-
assertFalse("Unexpected start executable "+startExecutable, containsSame(executables, startExecutable));
176+
assertFalse(containsSame(executables, startExecutable), "Unexpected start executable "+startExecutable);
177177
//check that some method was found
178178
assertFalse(executables.isEmpty());
179179
//check that expected methods were found and remove them
180180
expectedExecutables.forEach(m->{
181181
boolean found = removeSame(executables, m);
182182
if(startExecutable==m) {
183183
//it is start method. It should not be there
184-
assertFalse("The signature "+getQSignature(m)+" was returned too", found);
184+
assertFalse(found, "The signature "+getQSignature(m)+" was returned too");
185185
} else {
186-
assertTrue("The signature "+getQSignature(m)+" not found", found);
186+
assertTrue(found, "The signature "+getQSignature(m)+" not found");
187187
}
188188
});
189189
//check that there is no unexpected executable
190-
assertTrue("Unexpected executables: "+executables, executables.isEmpty());
190+
assertTrue(executables.isEmpty(), "Unexpected executables: "+executables);
191191
}
192192

193193
//contract: check that includingSelf(true) returns startMethod too
194194
//contract: check that by default it still returns lambdas
195195
{
196196
final List<CtExecutable<?>> executables = startExecutable.map(new AllMethodsSameSignatureFunction().includingSelf(true)).list();
197-
assertTrue("Missing start executable "+startExecutable, containsSame(executables, startExecutable));
197+
assertTrue(containsSame(executables, startExecutable), "Missing start executable "+startExecutable);
198198
//check that some method was found
199199
assertFalse(executables.isEmpty());
200200
//check that expected methods were found and remove them
201201
expectedExecutables.forEach(m->{
202-
assertTrue("The signature "+getQSignature(m)+" not found", removeSame(executables, m));
202+
assertTrue(removeSame(executables, m), "The signature "+getQSignature(m)+" not found");
203203
});
204204
//check that there is no unexpected executable
205-
assertTrue("Unexpected executables: "+executables, executables.isEmpty());
205+
assertTrue(executables.isEmpty(), "Unexpected executables: "+executables);
206206
}
207207

208208
//contract: check that includingLambdas(false) returns no lambda expressions
209209
{
210210
final List<CtExecutable<?>> executables = startExecutable.map(new AllMethodsSameSignatureFunction().includingSelf(true).includingLambdas(false)).list();
211211
if (startExecutable instanceof CtLambda) {
212212
//lambda must not be returned even if it is first
213-
assertFalse("Unexpected start executable "+startExecutable, containsSame(executables, startExecutable));
213+
assertFalse(containsSame(executables, startExecutable), "Unexpected start executable "+startExecutable);
214214
} else {
215-
assertTrue("Missing start executable "+startExecutable, containsSame(executables, startExecutable));
215+
assertTrue(containsSame(executables, startExecutable), "Missing start executable "+startExecutable);
216216
}
217217

218218
//check that some method was found
@@ -223,10 +223,10 @@ private void checkMethodHierarchy(List<CtExecutable<?>> expectedExecutables, CtE
223223
//the lambdas are not expected. Do not ask for them
224224
return;
225225
}
226-
assertTrue("The signature "+getQSignature(m)+" not found", removeSame(executables, m));
226+
assertTrue(removeSame(executables, m), "The signature "+getQSignature(m)+" not found");
227227
});
228228
//check that there is no unexpected executable or lambda
229-
assertTrue("Unexepcted executables "+executables, executables.isEmpty());
229+
assertTrue(executables.isEmpty(), "Unexepcted executables "+executables);
230230
}
231231
//contract: check early termination
232232
//contract: check that first returned element is the startExecutable itself if includingSelf == true
@@ -301,7 +301,7 @@ private int checkExecutableReferenceFilter(Factory factory, List<CtExecutable<?>
301301
return containsSame(executables, er.getDeclaration());
302302
}).forEach((CtExecutableReference er)->{
303303
//check that each expected reference was found by ExecutableReferenceFilter and remove it from that list
304-
assertTrue("Executable reference: "+er+" not found.", refs.remove(er));
304+
assertTrue(refs.remove(er), "Executable reference: "+er+" not found.");
305305
});
306306
//check that no other reference was found by ExecutableReferenceFilter
307307
assertSame(0, refs.size());

src/test/java/spoon/test/refactoring/RefactoringTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
package spoon.test.refactoring;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.io.File;
2626
import java.nio.file.Files;

0 commit comments

Comments
 (0)