Skip to content

Commit 8e66b87

Browse files
committed
NUTCH-2887 Migrate to JUnit 5 Jupiter
1 parent 4915b8a commit 8e66b87

69 files changed

Lines changed: 941 additions & 923 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.

‎build.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@
487487
<copy file="${test.src.dir}/filter-all.txt" todir="${test.build.classes}"/>
488488
<junitlauncher printSummary="true" haltOnFailure="true" failureProperty="tests.failed">
489489
<classpath refid="test.classpath"/>
490-
<testclasses outputDir="${test.build.dir}" unless="testcase" includeEngines="junit-jupiter">
490+
<testclasses outputDir="${test.build.dir}" unless="testcase">
491491
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
492492
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
493493
<fork>
@@ -502,7 +502,7 @@
502502
<exclude name="**/${test.exclude}.class"/>
503503
</fileset>
504504
</testclasses>
505-
<testclasses outputDir="${test.build.dir}" if="testcase" includeEngines="junit-jupiter">
505+
<testclasses outputDir="${test.build.dir}" if="testcase">
506506
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
507507
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
508508
<fork>

‎ivy/ivy.xml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +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" />
121+
<dependency org="org.hamcrest" name="hamcrest" rev="3.0" conf="test->default"/>
123122
<!-- Required for <junitlauncher> task -->
124123
<dependency org="org.junit.platform" name="junit-platform-launcher" rev="1.13.4" conf="test->default"/>
125124
<!-- Required for JUnit 5 (Jupiter) test execution -->
126125
<dependency org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.13.4" conf="test->default"/>
127126
<dependency org="org.junit.jupiter" name="junit-jupiter-api" rev="5.13.4" conf="test->default"/>
128-
<!-- JUnit Vintage Engine (to run existing JUnit 4 tests). Remove once migration is complete -->
129-
<dependency org="org.junit.vintage" name="junit-vintage-engine" rev="5.13.4" conf="test->default"/>
130127
<dependency org="org.apache.mrunit" name="mrunit" rev="1.1.0" conf="test->default">
131128
<artifact name="mrunit" ns0:classifier="hadoop2" />
132129
<exclude org="log4j" module="log4j" />

‎src/plugin/build-plugin.xml‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@
8080
</fileset>
8181
<!-- global test dependencies -->
8282
<fileset dir="${nutch.root}/build/test/lib">
83+
<include name="apiguardian*.jar" />
8384
<include name="hamcrest*.jar" />
84-
<include name="junit-4*.jar" />
85-
<exclude name="junit-jupiter*.jar"/>
86-
<exclude name="apiguardian*.jar" />
87-
<exclude name="opentest4j*.jar" />
85+
<include name="junit*.jar" />
86+
<include name="opentest4j*.jar" />
8887
</fileset>
8988
<path refid="classpath"/>
9089
</path>
@@ -210,25 +209,9 @@
210209
<!-- ================================================================== -->
211210
<target name="test" depends="compile-test, deploy" if="test.available">
212211
<echo message="Testing plugin: ${name}"/>
213-
<junit printsummary="on" haltonfailure="on" haltonerror="on" fork="yes"
214-
errorProperty="tests.failed" failureProperty="tests.failed" logfailedtests="true">
215-
<sysproperty key="test.data" value="${build.test}/data"/>
216-
<sysproperty key="test.input" value="${root}/data"/>
217-
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
212+
<junitlauncher printSummary="true" haltOnFailure="true" failureProperty="tests.failed">
218213
<classpath refid="test.classpath"/>
219-
<formatter type="plain" />
220-
<batchtest todir="${build.test}" unless="testcase">
221-
<fileset dir="${src.test}"
222-
includes="**/Test*.java" excludes="**/${test.exclude}.java" />
223-
</batchtest>
224-
<batchtest todir="${build.test}" if="testcase">
225-
<fileset dir="${src.test}" includes="**/${testcase}.java"/>
226-
</batchtest>
227-
</junit>
228-
<!-- TODO activate once JUnit 5 upgrade is complete in core -->
229-
<!--junitlauncher printSummary="true" haltOnFailure="true" failureProperty="tests.failed">
230-
<classpath refid="test.classpath"/>
231-
<testclasses outputDir="${build.test}" unless="testcase" includeEngines="junit-vintage">
214+
<testclasses outputDir="${build.test}" unless="testcase">
232215
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
233216
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
234217
<fork forkMode="perTestClass">
@@ -242,7 +225,7 @@
242225
<exclude name="**/${test.exclude}.class"/>
243226
</fileset>
244227
</testclasses>
245-
<testclasses outputDir="${build.test}" if="testcase" includeEngines="junit-vintage">
228+
<testclasses outputDir="${build.test}" if="testcase">
246229
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
247230
<listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
248231
<fork forkMode="perTestClass">
@@ -255,7 +238,7 @@
255238
<include name="**/${testcase}.class"/>
256239
</fileset>
257240
</testclasses>
258-
</junitlauncher-->
241+
</junitlauncher>
259242
<fail if="tests.failed">Tests failed!</fail>
260243
</target>
261244

‎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)