Skip to content

Commit cf1d848

Browse files
authored
Merge pull request #214 from strangelookingnerd/migrate_junit5
Migrate tests to JUnit5
2 parents 2041adb + 1b239b2 commit cf1d848

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+743
-270
lines changed

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<email>ggregory at apache.org</email>
6060
<url>https://www.garygregory.com</url>
6161
<organization>The Apache Software Foundation</organization>
62-
<organizationUrl>https://www.apache.org/</organizationUrl>
62+
<organizationUrl>https://www.apache.org/</organizationUrl>
6363
<roles>
6464
<role>PMC Member</role>
6565
</roles>
@@ -105,7 +105,7 @@
105105
<commons.jacoco.branchRatio>0.68</commons.jacoco.branchRatio>
106106
<commons.jacoco.lineRatio>0.77</commons.jacoco.lineRatio>
107107
<commons.jacoco.complexityRatio>0.64</commons.jacoco.complexityRatio>
108-
</properties>
108+
</properties>
109109
<build>
110110
<defaultGoal>clean apache-rat:check verify japicmp:cmp checkstyle:check pmd:check javadoc:javadoc</defaultGoal>
111111
<plugins>
@@ -157,7 +157,7 @@
157157
<link>https://commons.apache.org/proper/commons-beanutils/apidocs</link>
158158
<link>https://commons.apache.org/proper/commons-lang/apidocs</link>
159159
<!-- http://www.jdom.org/docs/apidocs/ is not a secure link -->
160-
<link>https://javadoc.io/doc/org.jdom/jdom/1.1</link>
160+
<link>https://javadoc.io/doc/org.jdom/jdom/1.1</link>
161161
</links>
162162
</configuration>
163163
</plugin>
@@ -215,9 +215,9 @@
215215
<optional>true</optional>
216216
</dependency>
217217
<dependency>
218-
<groupId>junit</groupId>
219-
<artifactId>junit</artifactId>
220-
<version>4.13.2</version>
218+
<groupId>org.junit.jupiter</groupId>
219+
<artifactId>junit-jupiter-engine</artifactId>
220+
<version>5.11.4</version>
221221
<scope>test</scope>
222222
</dependency>
223223
<dependency>
@@ -310,7 +310,7 @@
310310
<link>http://java.sun.com/j2se/1.3/docs/api/</link>
311311
<link>http://java.sun.com/javaee/5/docs/api/</link>
312312
<link>http://commons.apache.org/beanutils/apidocs/</link>
313-
<link>http://www.jdom.org/docs/apidocs/</link>
313+
<link>http://www.jdom.org/docs/apidocs/</link>
314314
</links>
315315
</configuration>
316316
</plugin>

src/test/java/org/apache/commons/jxpath/AbstractJXPathTest.java

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@
2626
import java.util.Set;
2727

2828
import org.apache.commons.jxpath.ri.model.NodePointer;
29+
import org.junit.jupiter.api.BeforeEach;
2930

30-
import junit.framework.TestCase;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
3133

3234
/**
3335
* Abstract superclass for various JXPath tests.
3436
*/
35-
public abstract class AbstractJXPathTest extends TestCase {
37+
public abstract class AbstractJXPathTest {
3638

3739
/**
3840
* Constructs a new instance of this test case.
41+
*
42+
* @throws Exception In case of errors during setup
3943
*/
40-
public AbstractJXPathTest() {
44+
@BeforeEach
45+
protected void setUp() throws Exception
46+
{
4147
Locale.setDefault(Locale.US);
4248
}
4349

@@ -46,15 +52,15 @@ protected void assertXPathValue(final JXPathContext ctx,
4652
{
4753
ctx.setLenient(false);
4854
final Object actual = ctx.getValue(xpath);
49-
assertEquals("Evaluating <" + xpath + ">", expected, actual);
55+
assertEquals(expected, actual, "Evaluating <" + xpath + ">");
5056
}
5157

5258
protected void assertXPathValue(final JXPathContext ctx,
5359
final String xpath, final Object expected, final Class resultType)
5460
{
5561
ctx.setLenient(false);
5662
final Object actual = ctx.getValue(xpath, resultType);
57-
assertEquals("Evaluating <" + xpath + ">", expected, actual);
63+
assertEquals(expected, actual, "Evaluating <" + xpath + ">");
5864
}
5965

6066
protected void assertXPathValueLenient(final JXPathContext ctx,
@@ -63,7 +69,7 @@ protected void assertXPathValueLenient(final JXPathContext ctx,
6369
ctx.setLenient(true);
6470
final Object actual = ctx.getValue(xpath);
6571
ctx.setLenient(false);
66-
assertEquals("Evaluating lenient <" + xpath + ">", expected, actual);
72+
assertEquals(expected, actual, "Evaluating lenient <" + xpath + ">");
6773
}
6874

6975
protected void assertXPathSetValue(final JXPathContext ctx,
@@ -77,37 +83,37 @@ protected void assertXPathSetValue(final JXPathContext ctx,
7783
{
7884
ctx.setValue(xpath, value);
7985
final Object actual = ctx.getValue(xpath);
80-
assertEquals("Modifying <" + xpath + ">", expected, actual);
86+
assertEquals(expected, actual, "Modifying <" + xpath + ">");
8187
}
8288

8389
protected void assertXPathCreatePath(final JXPathContext ctx,
8490
final String xpath,
8591
final Object expectedValue, final String expectedPath)
8692
{
8793
final Pointer pointer = ctx.createPath(xpath);
88-
assertEquals("Creating path <" + xpath + ">",
89-
expectedPath, pointer.asPath());
94+
assertEquals(expectedPath, pointer.asPath(),
95+
"Creating path <" + xpath + ">");
9096

91-
assertEquals("Creating path (pointer value) <" + xpath + ">",
92-
expectedValue, pointer.getValue());
97+
assertEquals(expectedValue, pointer.getValue(),
98+
"Creating path (pointer value) <" + xpath + ">");
9399

94-
assertEquals("Creating path (context value) <" + xpath + ">",
95-
expectedValue, ctx.getValue(pointer.asPath()));
100+
assertEquals(expectedValue, ctx.getValue(pointer.asPath()),
101+
"Creating path (context value) <" + xpath + ">");
96102
}
97103

98104
protected void assertXPathCreatePathAndSetValue(final JXPathContext ctx,
99105
final String xpath, final Object value,
100106
final String expectedPath)
101107
{
102108
final Pointer pointer = ctx.createPathAndSetValue(xpath, value);
103-
assertEquals("Creating path <" + xpath + ">",
104-
expectedPath, pointer.asPath());
109+
assertEquals(expectedPath, pointer.asPath(),
110+
"Creating path <" + xpath + ">");
105111

106-
assertEquals("Creating path (pointer value) <" + xpath + ">",
107-
value, pointer.getValue());
112+
assertEquals(value, pointer.getValue(),
113+
"Creating path (pointer value) <" + xpath + ">");
108114

109-
assertEquals("Creating path (context value) <" + xpath + ">",
110-
value, ctx.getValue(pointer.asPath()));
115+
assertEquals(value, ctx.getValue(pointer.asPath()),
116+
"Creating path (context value) <" + xpath + ">");
111117
}
112118

113119
protected void assertXPathPointer(final JXPathContext ctx,
@@ -116,7 +122,7 @@ protected void assertXPathPointer(final JXPathContext ctx,
116122
ctx.setLenient(false);
117123
final Pointer pointer = ctx.getPointer(xpath);
118124
final String actual = pointer.toString();
119-
assertEquals("Evaluating pointer <" + xpath + ">", expected, actual);
125+
assertEquals(expected, actual, "Evaluating pointer <" + xpath + ">");
120126
}
121127

122128
protected void assertXPathPointerLenient(final JXPathContext ctx,
@@ -125,7 +131,7 @@ protected void assertXPathPointerLenient(final JXPathContext ctx,
125131
ctx.setLenient(true);
126132
final Pointer pointer = ctx.getPointer(xpath);
127133
final String actual = pointer.toString();
128-
assertEquals("Evaluating pointer <" + xpath + ">", expected, actual);
134+
assertEquals(expected, actual, "Evaluating pointer <" + xpath + ">");
129135
}
130136

131137
protected void assertXPathValueAndPointer(final JXPathContext ctx,
@@ -148,10 +154,12 @@ protected <E> void assertXPathValueIterator(final JXPathContext ctx,
148154
while (it.hasNext()) {
149155
actual.add(it.next());
150156
}
151-
assertEquals(String.format("[hashCode()] Evaluating value iterator <%s>, expected.class %s(%,d): %s, actual.class %s(%,d): %s", xpath,
152-
expected.getClass(), expected.size(), expected, actual.getClass(), actual.size(), actual), expected.hashCode(), actual.hashCode());
153-
assertEquals(String.format("[equals()] Evaluating value iterator <%s>, expected.class %s(%,d): %s, actual.class %s(%,d): %s", xpath,
154-
expected.getClass(), expected.size(), expected, actual.getClass(), actual.size(), actual), expected, actual);
157+
assertEquals(expected.hashCode(), actual.hashCode(),
158+
String.format("[hashCode()] Evaluating value iterator <%s>, expected.class %s(%,d): %s, actual.class %s(%,d): %s", xpath,
159+
expected.getClass(), expected.size(), expected, actual.getClass(), actual.size(), actual));
160+
assertEquals(expected, actual,
161+
String.format("[equals()] Evaluating value iterator <%s>, expected.class %s(%,d): %s, actual.class %s(%,d): %s", xpath,
162+
expected.getClass(), expected.size(), expected, actual.getClass(), actual.size(), actual));
155163
}
156164

157165
protected void assertXPathPointerIterator(
@@ -172,9 +180,9 @@ protected void assertXPathPointerIterator(
172180
actual.add(pointer.toString());
173181
}
174182
assertEquals(
175-
"Evaluating pointer iterator <" + xpath + ">",
176183
expected,
177-
actual);
184+
actual,
185+
"Evaluating pointer iterator <" + xpath + ">");
178186
}
179187

180188
protected void assertDocumentOrder(
@@ -193,9 +201,9 @@ else if (res > 0) {
193201
res = 1;
194202
}
195203
assertEquals(
196-
"Comparing paths '" + path1 + "' and '" + path2 + "'",
197204
expected,
198-
res);
205+
res,
206+
"Comparing paths '" + path1 + "' and '" + path2 + "'");
199207
}
200208

201209
protected void assertXPathValueType(
@@ -205,8 +213,7 @@ protected void assertXPathValueType(
205213
{
206214
ctx.setLenient(false);
207215
final Object actual = ctx.getValue(xpath);
208-
assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(),
209-
clazz.isAssignableFrom(actual.getClass()));
216+
assertTrue(clazz.isAssignableFrom(actual.getClass()), "Evaluating <" + xpath + "> = " + actual.getClass());
210217
}
211218

212219
protected void assertXPathNodeType(
@@ -216,8 +223,8 @@ protected void assertXPathNodeType(
216223
{
217224
ctx.setLenient(false);
218225
final Pointer actual = ctx.getPointer(xpath);
219-
assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(),
220-
clazz.isAssignableFrom(actual.getNode().getClass()));
226+
assertTrue(clazz.isAssignableFrom(actual.getNode().getClass()),
227+
"Evaluating <" + xpath + "> = " + actual.getNode().getClass());
221228
}
222229

223230
protected static List list() {

src/test/java/org/apache/commons/jxpath/BasicNodeSetTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import java.util.Iterator;
2020
import java.util.List;
2121

22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2224
import org.w3c.dom.Element;
2325

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
2428
/**
2529
* Test BasicNodeSet
2630
*/
@@ -33,6 +37,7 @@ public class BasicNodeSetTest extends AbstractJXPathTest {
3337
protected BasicNodeSet nodeSet;
3438

3539
@Override
40+
@BeforeEach
3641
protected void setUp() throws Exception {
3742
super.setUp();
3843
context = JXPathContext.newContext(new TestMixedModelBean());
@@ -75,10 +80,12 @@ protected void nudge() {
7580
/**
7681
* Test adding pointers.
7782
*/
83+
@Test
7884
public void testAdd() {
7985
addPointers("/bean/integers");
80-
assertEquals(nodeSet.getPointers().toString(), list("/bean/integers[1]",
81-
"/bean/integers[2]", "/bean/integers[3]", "/bean/integers[4]").toString());
86+
assertEquals(list("/bean/integers[1]",
87+
"/bean/integers[2]", "/bean/integers[3]", "/bean/integers[4]").toString(),
88+
nodeSet.getPointers().toString());
8289
assertEquals(list(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3),
8390
Integer.valueOf(4)), nodeSet.getValues());
8491
assertEquals(list(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3),
@@ -88,6 +95,7 @@ public void testAdd() {
8895
/**
8996
* Test removing a pointer.
9097
*/
98+
@Test
9199
public void testRemove() {
92100
addPointers("/bean/integers");
93101
removePointers("/bean/integers[4]");
@@ -102,6 +110,7 @@ public void testRemove() {
102110
/**
103111
* Demonstrate when nodes != values: in XML models.
104112
*/
113+
@Test
105114
public void testNodes() {
106115
addPointers("/document/vendor/contact");
107116
assertEquals(list("/document/vendor[1]/contact[1]",

src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424

2525
import org.apache.commons.jxpath.JXPathContext;
2626
import org.apache.commons.jxpath.AbstractJXPathTest;
27+
import org.junit.jupiter.api.Test;
2728
import org.w3c.dom.Document;
2829
import org.xml.sax.InputSource;
2930

3031
public class JXPath113Test extends AbstractJXPathTest
3132
{
3233

34+
@Test
3335
public void testIssue113() throws Exception
3436
{
3537
final Document doc = JAXP.getDocument("<xml/>");

src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@
2121
import org.apache.commons.jxpath.JXPathContext;
2222
import org.apache.commons.jxpath.Pointer;
2323

24-
import junit.framework.Assert;
25-
import junit.framework.TestCase;
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2627

2728
/**
2829
* Testcase proving JXPATH-118 issue with asPath() returning wrong names.
2930
*/
30-
public class JXPath118Test extends TestCase
31+
public class JXPath118Test
3132
{
3233

34+
@Test
3335
public void testJXPATH118IssueWithAsPath() throws Exception
3436
{
3537
final Object contextBean = new SomeChildClass();
3638
final JXPathContext context = JXPathContext.newContext(contextBean);
3739
final Iterator<Pointer> iteratePointers = context.iteratePointers("//*");
38-
Assert.assertEquals("/bar", iteratePointers.next().asPath());
39-
Assert.assertEquals("/baz", iteratePointers.next().asPath());
40-
Assert.assertEquals("/foo", iteratePointers.next().asPath());
40+
assertEquals("/bar", iteratePointers.next().asPath());
41+
assertEquals("/baz", iteratePointers.next().asPath());
42+
assertEquals("/foo", iteratePointers.next().asPath());
4143
}
4244

4345
public static class SomeChildClass

src/test/java/org/apache/commons/jxpath/issues/JXPath149Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import org.apache.commons.jxpath.JXPathContext;
2020
import org.apache.commons.jxpath.AbstractJXPathTest;
21+
import org.junit.jupiter.api.Test;
2122

2223
public class JXPath149Test extends AbstractJXPathTest {
2324

25+
@Test
2426
public void testComplexOperationWithVariables() {
2527
final JXPathContext context = JXPathContext.newContext(null);
2628
context.getVariables().declareVariable("a", Integer.valueOf(0));

0 commit comments

Comments
 (0)