Skip to content

Commit 9d473b4

Browse files
BananeweizenCalixte
authored andcommitted
Use JUnit 5
Change all dependencies for Maven and Eclipse from JUnit 4 to JUnit 5 and convert all the JUnit API to JUnit Jupiter. This allows running the existing tests as JUnit 5 tests in Maven and Eclipse (given a recent Eclipse IDE).
1 parent 1c057d1 commit 9d473b4

26 files changed

+296
-188
lines changed

net.sf.eclipsecs.checkstyle/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<attribute name="test" value="true"/>
1414
</attributes>
1515
</classpathentry>
16-
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
16+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
1717
<classpathentry kind="output" path="target/classes"/>
1818
</classpath>

net.sf.eclipsecs.checkstyle/test/net/sf/eclipsecs/checkstyle/ChecksTest.java

Lines changed: 66 additions & 84 deletions
Large diffs are not rendered by default.

net.sf.eclipsecs.checkstyle/test/net/sf/eclipsecs/checkstyle/utils/XmlUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package net.sf.eclipsecs.checkstyle.utils;
22

3+
import static org.junit.jupiter.api.Assertions.fail;
4+
35
import java.io.IOException;
46
import java.io.StringReader;
57
import java.util.LinkedHashSet;
68
import java.util.Set;
79
import java.util.stream.Collectors;
810

9-
import org.junit.Assert;
1011
import org.w3c.dom.Document;
1112
import org.w3c.dom.Node;
1213
import org.xml.sax.EntityResolver;
@@ -42,7 +43,7 @@ public InputSource resolveEntity(String publicId, String systemId)
4243

4344
rawXml = builder.parse(new InputSource(new StringReader(code)));
4445
} catch (IOException | SAXException ex) {
45-
Assert.fail(fileName + " has invalid xml (" + ex.getMessage() + "): " + unserializedSource);
46+
fail(fileName + " has invalid xml (" + ex.getMessage() + "): " + unserializedSource);
4647
}
4748

4849
return rawXml;

net.sf.eclipsecs.target/net.sf.eclipsecs.target.target

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<?pde?>
3-
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
4-
<target name="Eclipse Checkstyle" sequenceNumber="1590429360">
3+
<!-- generated with https://github.com/mbarbero/fr.obeo.releng.targetplatform -->
4+
<target name="Eclipse Checkstyle" sequenceNumber="1591014598">
55
<locations>
66
<location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
77
<unit id="org.eclipse.jdt.feature.group" version="0.0.0"/>
88
<unit id="org.eclipse.sdk.ide" version="0.0.0"/>
99
<unit id="org.eclipse.emf.feature.group" version="0.0.0"/>
10-
<repository location="http://download.eclipse.org/releases/juno/201303010900/"/>
10+
<repository location="https://download.eclipse.org/releases/juno/201303010900/"/>
11+
</location>
12+
<location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
13+
<unit id="org.junit.jupiter.api" version="0.0.0"/>
14+
<unit id="org.junit.jupiter.engine" version="0.0.0"/>
15+
<unit id="org.junit.jupiter.params" version="0.0.0"/>
16+
<unit id="org.junit.platform.commons" version="0.0.0"/>
17+
<unit id="org.junit.platform.engine" version="0.0.0"/>
18+
<unit id="org.junit.platform.launcher" version="0.0.0"/>
19+
<unit id="org.junit.platform.runner" version="0.0.0"/>
20+
<unit id="org.junit.platform.suite.api" version="0.0.0"/>
21+
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20200529191137/repository"/>
1122
</location>
1223
</locations>
1324
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
// Install http://download.eclipse.org/cbi/tpd/3.0.0-SNAPSHOT/ to use this target definition.
1+
// Install https://download.eclipse.org/cbi/tpd/3.0.0-SNAPSHOT/ to use this target definition.
22
// Read https://github.com/eclipse-cbi/targetplatform-dsl for more details.
33
target "Eclipse Checkstyle"
44
with source configurePhase
55
environment JavaSE-1.8
66

77
// use the latest version of Juno only, to avoid downloading all children of the Juno composite update site
8-
location "http://download.eclipse.org/releases/juno/201303010900/" {
8+
location "https://download.eclipse.org/releases/juno/201303010900/" {
99
org.eclipse.jdt.feature.group lazy
1010
org.eclipse.sdk.ide lazy
1111

1212
// e4.ui has dependencies to EMF, those are not actually needed by eclipse-cs itself
1313
org.eclipse.emf.feature.group lazy
1414
}
15+
16+
// latest release of JUnit 5 from Eclipse Orbit
17+
location "https://download.eclipse.org/tools/orbit/downloads/drops/R20200529191137/repository" {
18+
org.junit.jupiter.api lazy
19+
org.junit.jupiter.engine lazy
20+
org.junit.jupiter.params lazy
21+
org.junit.platform.commons lazy
22+
org.junit.platform.engine lazy
23+
org.junit.platform.launcher lazy
24+
org.junit.platform.runner lazy
25+
org.junit.platform.suite.api lazy
26+
}

net.sf.eclipsecs.ui/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<classpathentry exported="true" kind="lib" path="lib/jfreechart-1.0.19.jar"/>
1616
<classpathentry exported="true" kind="lib" path="lib/jfreechart-1.0.19-swt.jar"/>
1717
<classpathentry exported="true" kind="lib" path="lib/jcommon-1.0.23.jar"/>
18-
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
18+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
1919
<classpathentry kind="output" path="target/classes"/>
2020
</classpath>

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.google.common.base.Strings;
44

5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
58
import java.io.InputStream;
69
import java.util.ArrayList;
710
import java.util.HashMap;
@@ -16,22 +19,20 @@
1619
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
1720
import org.eclipse.jface.text.IRegion;
1821
import org.eclipse.text.edits.TextEdit;
19-
import org.junit.Assert;
2022
import org.w3c.dom.Document;
2123
import org.w3c.dom.Element;
2224
import org.w3c.dom.NodeList;
2325

2426
import javax.xml.parsers.DocumentBuilder;
2527
import javax.xml.parsers.DocumentBuilderFactory;
26-
import junit.framework.TestCase;
2728

28-
public abstract class AbstractQuickfixTestCase extends TestCase {
29+
public abstract class AbstractQuickfixTestCase {
2930

3031
protected void testQuickfix(final String testDataXml, final AbstractASTResolution quickfix)
3132
throws Exception {
3233
InputStream stream = getClass().getResourceAsStream(testDataXml);
33-
assertNotNull("Cannot find resource " + testDataXml + " in package "
34-
+ getClass().getPackage().getName(), stream);
34+
assertNotNull(stream, "Cannot find resource " + testDataXml + " in package "
35+
+ getClass().getPackage().getName());
3536
try {
3637
System.out.println(
3738
"Test quickfix " + quickfix.getClass() + " with input file `" + testDataXml + "`");
@@ -73,7 +74,7 @@ protected void testQuickfix(InputStream testdataStream, AbstractASTResolution qu
7374
TextEdit edit = compUnit.rewrite(doc, options);
7475
edit.apply(doc);
7576

76-
Assert.assertEquals(testdata[i].result, doc.get());
77+
assertEquals(testdata[i].result, doc.get());
7778
}
7879

7980
}

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

22
package net.sf.eclipsecs.ui.quickfixes.blocks;
33

4+
import org.junit.jupiter.api.Test;
5+
46
import net.sf.eclipsecs.ui.quickfixes.AbstractQuickfixTestCase;
57

68
public class AvoidNestedBlocksTest extends AbstractQuickfixTestCase {
79

10+
@Test
811
public void testAvoidNestedBlocks() throws Exception {
912
testQuickfix("AvoidNestedBlocksInput.xml", new AvoidNestedBlocksQuickfix());
1013
}

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11

22
package net.sf.eclipsecs.ui.quickfixes.blocks;
33

4+
import org.junit.jupiter.api.Test;
5+
46
import net.sf.eclipsecs.ui.quickfixes.AbstractQuickfixTestCase;
57

68
public class NeedBracesTest extends AbstractQuickfixTestCase {
79

10+
@Test
811
public void testNeedBracesIf() throws Exception {
912
testQuickfix("NeedBracesInputIf.xml", new NeedBracesQuickfix());
1013
}
1114

15+
@Test
1216
public void testNeedBracesElse() throws Exception {
1317
testQuickfix("NeedBracesInputElse.xml", new NeedBracesQuickfix());
1418
}
1519

20+
@Test
1621
public void testNeedBracesElseIf() throws Exception {
1722
testQuickfix("NeedBracesInputElseIf.xml", new NeedBracesQuickfix());
1823
}
1924

25+
@Test
2026
public void testNeedBracesFor() throws Exception {
2127
testQuickfix("NeedBracesInputFor.xml", new NeedBracesQuickfix());
2228
}
2329

30+
@Test
2431
public void testNeedBracesWhile() throws Exception {
2532
testQuickfix("NeedBracesInputWhile.xml", new NeedBracesQuickfix());
2633
}
2734

35+
@Test
2836
public void testNeedBracesDoWhile() throws Exception {
2937
testQuickfix("NeedBracesInputDoWhile.xml", new NeedBracesQuickfix());
3038
}

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

22
package net.sf.eclipsecs.ui.quickfixes.coding;
33

4+
import org.junit.jupiter.api.Test;
5+
46
import net.sf.eclipsecs.ui.quickfixes.AbstractQuickfixTestCase;
57

68
public class DefaultComesLastTest extends AbstractQuickfixTestCase {
79

10+
@Test
811
public void testDefaultComesLast() throws Exception {
912
testQuickfix("DefaultComesLastInput.xml", new DefaultComesLastQuickfix());
1013
}
1114

15+
@Test
1216
public void testDefaultComesLastInner() throws Exception {
1317
testQuickfix("DefaultComesLastInputInner.xml", new DefaultComesLastQuickfix());
1418
}

0 commit comments

Comments
 (0)