Skip to content

Commit e2b60fc

Browse files
authored
NUTCH-2887 Migrate to JUnit 5 Jupiter (#862)
1 parent 4c04a98 commit e2b60fc

115 files changed

Lines changed: 1751 additions & 1667 deletions

File tree

Some content is hidden

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

‎.github/workflows/master-build.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
java: ['11']
6666
os: [ubuntu-latest, macos-latest]
6767
runs-on: ${{ matrix.os }}
68+
timeout-minutes: 30
6869
steps:
6970
- uses: actions/checkout@v4.2.2
7071
- name: Set up JDK ${{ matrix.java }}

‎build.xml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@
485485
<copy file="${test.src.dir}/crawl-tests.xml" todir="${test.build.classes}"/>
486486
<copy file="${test.src.dir}/domain-urlfilter.txt" todir="${test.build.classes}"/>
487487
<copy file="${test.src.dir}/filter-all.txt" todir="${test.build.classes}"/>
488-
489488
<junitlauncher printSummary="true" haltOnFailure="true" failureProperty="tests.failed">
490489
<classpath refid="test.classpath"/>
491-
<testclasses outputDir="${test.build.dir}" unless="testcase" includeEngines="junit-vintage">
492-
<listener type="${test.junit.output.format}" sendSysOut="true" sendSysErr="true"/>
493-
<fork dir="${basedir}">
490+
<testclasses outputDir="${test.build.dir}" unless="testcase">
491+
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
492+
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
493+
<fork>
494494
<jvmarg value="-Xmx1000m"/>
495495
<sysproperty key="test.build.data" value="${test.build.data}"/>
496496
<sysproperty key="test.src.dir" value="${test.src.dir}"/>
@@ -502,9 +502,10 @@
502502
<exclude name="**/${test.exclude}.class"/>
503503
</fileset>
504504
</testclasses>
505-
<testclasses outputDir="${test.build.dir}" if="testcase" includeEngines="junit-vintage">
506-
<listener type="${test.junit.output.format}" sendSysOut="true" sendSysErr="true"/>
507-
<fork dir="${basedir}">
505+
<testclasses outputDir="${test.build.dir}" if="testcase">
506+
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
507+
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
508+
<fork>
508509
<jvmarg value="-Xmx1000m"/>
509510
<sysproperty key="test.build.data" value="${test.build.data}"/>
510511
<sysproperty key="test.src.dir" value="${test.src.dir}"/>
@@ -516,7 +517,6 @@
516517
</fileset>
517518
</testclasses>
518519
</junitlauncher>
519-
520520
<fail if="tests.failed">Tests failed!</fail>
521521
</target>
522522

‎default.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ test.build.lib.dir = ${test.build.dir}/lib
3838
test.build.data = ${test.build.dir}/data
3939
test.build.classes = ${test.build.dir}/classes
4040
test.build.javadoc = ${test.build.dir}/docs/api
41-
test.junit.output.format = legacy-plain
4241

4342
# Proxy Host and Port to use for building JavaDoc
4443
javadoc.proxy.host=-J-DproxyHost=

‎ivy/ivy.xml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
<exclude org="org.gnu.inet" module="libidn" /><!-- LGPL 2.1 -->
119119
</dependency>
120120

121-
<!-- Keep the JUnit 4 dependency for test compilation and runtime support. Remove once migration is complete -->
122-
<dependency org="junit" name="junit" rev="4.13.2" conf="test->default" />
123-
<!-- JUnit 5 Platform Launcher (required for <junitlauncher> task) -->
121+
<dependency org="org.hamcrest" name="hamcrest" rev="3.0" conf="test->default"/>
122+
<!-- Required for <junitlauncher> task -->
124123
<dependency org="org.junit.platform" name="junit-platform-launcher" rev="1.13.4" conf="test->default"/>
125-
<!-- JUnit Vintage Engine (to run existing JUnit 4 tests). Remove once migration is complete -->
126-
<dependency org="org.junit.vintage" name="junit-vintage-engine" rev="5.13.4" conf="test->default"/>
124+
<!-- Required for JUnit 5 (Jupiter) test execution -->
125+
<dependency org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.13.4" conf="test->default"/>
126+
<dependency org="org.junit.jupiter" name="junit-jupiter-api" rev="5.13.4" conf="test->default"/>
127127
<dependency org="org.apache.mrunit" name="mrunit" rev="1.1.0" conf="test->default">
128128
<artifact name="mrunit" ns0:classifier="hadoop2" />
129129
<exclude org="log4j" module="log4j" />

‎src/plugin/build-plugin.xml‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
</fileset>
8181
<!-- global test dependencies -->
8282
<fileset dir="${nutch.root}/build/test/lib">
83+
<include name="apiguardian*.jar" />
8384
<include name="hamcrest*.jar" />
8485
<include name="junit*.jar" />
8586
<include name="opentest4j*.jar" />
@@ -208,28 +209,13 @@
208209
<!-- ================================================================== -->
209210
<target name="test" depends="compile-test, deploy" if="test.available">
210211
<echo message="Testing plugin: ${name}"/>
211-
212-
<!--junit printsummary="yes" haltonfailure="no" fork="yes"
213-
errorProperty="tests.failed" failureProperty="tests.failed">
214-
<sysproperty key="test.data" value="${build.test}/data"/>
215-
<sysproperty key="test.input" value="${root}/data"/>
216-
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
217-
<classpath refid="test.classpath"/>
218-
<formatter type="${test.junit.output.format}" />
219-
<batchtest todir="${build.test}" unless="testcase">
220-
<fileset dir="${src.test}"
221-
includes="**/Test*.java" excludes="**/${test.exclude}.java" />
222-
</batchtest>
223-
<batchtest todir="${build.test}" if="testcase">
224-
<fileset dir="${src.test}" includes="**/${testcase}.java"/>
225-
</batchtest>
226-
</junit-->
227-
228212
<junitlauncher printSummary="true" haltOnFailure="true" failureProperty="tests.failed">
229213
<classpath refid="test.classpath"/>
230214
<testclasses outputDir="${build.test}" unless="testcase">
231-
<listener type="${test.junit.output.format}" sendSysOut="true" sendSysErr="true"/>
232-
<fork dir="${basedir}">
215+
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
216+
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
217+
<fork forkMode="perTestClass">
218+
<jvmarg value="-Xmx1000m"/>
233219
<sysproperty key="test.data" value="${build.test}/data"/>
234220
<sysproperty key="test.input" value="${root}/data"/>
235221
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
@@ -240,18 +226,19 @@
240226
</fileset>
241227
</testclasses>
242228
<testclasses outputDir="${build.test}" if="testcase">
243-
<listener type="${test.junit.output.format}" sendSysOut="true" sendSysErr="true"/>
244-
<fork dir="${basedir}">
229+
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
230+
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
231+
<fork forkMode="perTestClass">
232+
<jvmarg value="-Xmx1000m"/>
245233
<sysproperty key="test.data" value="${build.test}/data"/>
246234
<sysproperty key="test.input" value="${root}/data"/>
247235
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
248236
</fork>
249-
<fileset dir="${build.test}">
237+
<fileset dir="${basedir}">
250238
<include name="**/${testcase}.class"/>
251239
</fileset>
252240
</testclasses>
253241
</junitlauncher>
254-
255242
<fail if="tests.failed">Tests failed!</fail>
256243
</target>
257244

‎src/plugin/creativecommons/src/test/org/creativecommons/nutch/TestCCParseFilter.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
import org.apache.nutch.protocol.Content;
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.nutch.util.NutchConfiguration;
25-
import org.junit.Assert;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2726

2827
import java.io.*;
2928

30-
public class TestCCParseFilter {
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
31+
class TestCCParseFilter {
3132

3233
private static final File testDir = new File(System.getProperty("test.input"));
3334

3435
@Test
35-
public void testPages() throws Exception {
36+
void testPages() throws Exception {
3637
pageTest(new File(testDir, "anchor.html"), "http://foo.com/",
3738
"http://creativecommons.org/licenses/by-nc-sa/1.0", "a", null);
3839
// Tika returns <a> whereas parse-html returns <rel>
@@ -65,8 +66,8 @@ public void pageTest(File file, String url, String license, String location,
6566
Parse parse = new ParseUtil(conf).parse(content).get(content.getUrl());
6667

6768
Metadata metadata = parse.getData().getParseMeta();
68-
Assert.assertEquals(license, metadata.get("License-Url"));
69-
Assert.assertEquals(location, metadata.get("License-Location"));
70-
Assert.assertEquals(type, metadata.get("Work-Type"));
69+
assertEquals(license, metadata.get("License-Url"));
70+
assertEquals(location, metadata.get("License-Location"));
71+
assertEquals(type, metadata.get("Work-Type"));
7172
}
7273
}

‎src/plugin/feed/src/test/org/apache/nutch/parse/feed/TestFeedParser.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import java.util.Iterator;
2020
import java.util.Map;
2121

22-
import org.junit.Assert;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2423

2524
import org.apache.hadoop.conf.Configuration;
2625
import org.apache.hadoop.io.Text;
@@ -35,6 +34,8 @@
3534
import org.apache.nutch.protocol.ProtocolNotFound;
3635
import org.apache.nutch.util.NutchConfiguration;
3736

37+
import static org.junit.jupiter.api.Assertions.*;
38+
3839
/**
3940
*
4041
* @author mattmann
@@ -86,7 +87,7 @@ public void testParseFetchChannel() throws ProtocolNotFound, ParseException {
8687

8788
parseResult = new ParseUtil(conf).parseByExtensionId("feed", content);
8889

89-
Assert.assertEquals(3, parseResult.size());
90+
assertEquals(3, parseResult.size());
9091

9192
boolean hasLink1 = false, hasLink2 = false, hasLink3 = false;
9293

@@ -102,12 +103,12 @@ public void testParseFetchChannel() throws ProtocolNotFound, ParseException {
102103
hasLink3 = true;
103104
}
104105

105-
Assert.assertNotNull(entry.getValue());
106-
Assert.assertNotNull(entry.getValue().getData());
106+
assertNotNull(entry.getValue());
107+
assertNotNull(entry.getValue().getData());
107108
}
108109

109110
if (!hasLink1 || !hasLink2 || !hasLink3) {
110-
Assert.fail("Outlinks read from sample rss file are not correct!");
111+
fail("Outlinks read from sample rss file are not correct!");
111112
}
112113
}
113114

‎src/plugin/headings/src/test/org/apache/nutch/parse/headings/TestHeadingsParseFilter.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
import java.io.ByteArrayInputStream;
2727
import java.io.IOException;
2828

29+
import org.junit.jupiter.api.Test;
2930
import org.w3c.dom.DocumentFragment;
3031
import org.xml.sax.InputSource;
3132
import org.xml.sax.SAXException;
3233
import org.cyberneko.html.parsers.DOMFragmentParser;
33-
import org.junit.Assert;
34-
import org.junit.Test;
34+
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
3536

3637
public class TestHeadingsParseFilter {
3738
private static Configuration conf = NutchConfiguration.create();
@@ -59,9 +60,8 @@ public void testExtractHeadingFromNestedNodes()
5960

6061
parseResult = filter.filter(content, parseResult, metaTags, node);
6162

62-
Assert.assertEquals(
63-
"The h1 tag must include the content of the inner span node",
64-
"header with span element",
65-
parseResult.get(content.getUrl()).getData().getParseMeta().get("h1"));
63+
assertEquals("header with span element",
64+
parseResult.get(content.getUrl()).getData().getParseMeta().get("h1"),
65+
"The h1 tag must include the content of the inner span node");
6666
}
6767
}

‎src/plugin/index-anchor/src/test/org/apache/nutch/indexer/anchor/TestAnchorIndexingFilter.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import org.apache.nutch.parse.ParseData;
2626
import org.apache.nutch.parse.ParseImpl;
2727
import org.apache.nutch.util.NutchConfiguration;
28-
import org.junit.Assert;
29-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
29+
30+
import static org.junit.jupiter.api.Assertions.*;
3031

3132
/**
3233
* JUnit test case which tests 1. that anchor text is obtained 2. that anchor
@@ -43,7 +44,7 @@ public void testDeduplicateAnchor() throws Exception {
4344
conf.setBoolean("anchorIndexingFilter.deduplicate", true);
4445
AnchorIndexingFilter filter = new AnchorIndexingFilter();
4546
filter.setConf(conf);
46-
Assert.assertNotNull(filter);
47+
assertNotNull(filter);
4748
NutchDocument doc = new NutchDocument();
4849
ParseImpl parse = new ParseImpl("foo bar", new ParseData());
4950
Inlinks inlinks = new Inlinks();
@@ -55,13 +56,12 @@ public void testDeduplicateAnchor() throws Exception {
5556
new CrawlDatum(), inlinks);
5657
} catch (Exception e) {
5758
e.printStackTrace();
58-
Assert.fail(e.getMessage());
59+
fail(e.getMessage());
5960
}
60-
Assert.assertNotNull(doc);
61-
Assert.assertTrue("test if there is an anchor at all", doc.getFieldNames()
62-
.contains("anchor"));
63-
Assert.assertEquals("test dedup, we expect 2", 2, doc.getField("anchor")
64-
.getValues().size());
61+
assertNotNull(doc);
62+
assertTrue(doc.getFieldNames().contains("anchor"), "test if there is an anchor at all");
63+
assertEquals(2, doc.getField("anchor").getValues().size(),
64+
"test dedup, we expect 2");
6565
}
6666

6767
}

0 commit comments

Comments
 (0)