summaryrefslogtreecommitdiff
path: root/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'test/java')
-rw-r--r--test/java/net/yacy/document/parser/GenericXMLParserTest.java108
-rw-r--r--test/java/net/yacy/document/parser/html/ContentScraperTest.java48
-rw-r--r--test/java/net/yacy/document/parser/ooxmlParserTest.java10
3 files changed, 83 insertions, 83 deletions
diff --git a/test/java/net/yacy/document/parser/GenericXMLParserTest.java b/test/java/net/yacy/document/parser/GenericXMLParserTest.java
index 3d2ae67a3..41115b304 100644
--- a/test/java/net/yacy/document/parser/GenericXMLParserTest.java
+++ b/test/java/net/yacy/document/parser/GenericXMLParserTest.java
@@ -58,7 +58,7 @@ public class GenericXMLParserTest {
@Before
public void setUp() {
- parser = new GenericXMLParser();
+ this.parser = new GenericXMLParser();
}
/**
@@ -73,11 +73,11 @@ public class GenericXMLParserTest {
final String[] fileNames = { "umlaute_dc_xml_iso.xml", "umlaute_dc_xml_utf8.xml" };
final File folder = new File("test" + File.separator + "parsertest" + File.separator);
- for (String fileName : fileNames) {
- FileInputStream inStream = new FileInputStream(new File(folder, fileName));
- DigestURL location = new DigestURL("http://localhost/" + fileName);
+ for (final String fileName : fileNames) {
+ final FileInputStream inStream = new FileInputStream(new File(folder, fileName));
+ final DigestURL location = new DigestURL("http://localhost/" + fileName);
try {
- Document[] documents = parser.parse(location, "text/xml", null, new VocabularyScraper(), 0,
+ final Document[] documents = this.parser.parse(location, "text/xml", null, new VocabularyScraper(), 0,
inStream);
assertNotNull("Parser result must not be null for file " + fileName, documents);
assertNotNull("Parsed text must not be empty for file " + fileName, documents[0].getTextString());
@@ -107,11 +107,11 @@ public class GenericXMLParserTest {
private void testCharsetDetection(final GenericXMLParser parser, final byte[] encodedXML,
final String contentTypeHeader, final String expectedCharset, final String expectedConntainedText)
throws Exception {
- InputStream inStream = new ByteArrayInputStream(encodedXML);
- String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
- DigestURL location = new DigestURL("http://localhost/testfile.xml");
+ final InputStream inStream = new ByteArrayInputStream(encodedXML);
+ final String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
+ final DigestURL location = new DigestURL("http://localhost/testfile.xml");
try {
- Document[] documents = parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
+ final Document[] documents = parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
new VocabularyScraper(), 0, inStream);
assertEquals(expectedCharset, documents[0].getCharset());
assertNotNull(documents[0].getTextString());
@@ -138,7 +138,7 @@ public class GenericXMLParserTest {
*/
byte[] encodedXML = ("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + UMLAUT_TEXT_TAG)
.getBytes(StandardCharsets.UTF_8);
- testCharsetDetection(parser, encodedXML, "application/xml; charset=utf-8", StandardCharsets.UTF_8.name(),
+ testCharsetDetection(this.parser, encodedXML, "application/xml; charset=utf-8", StandardCharsets.UTF_8.name(),
"Maßkrügen");
/*
@@ -146,7 +146,7 @@ public class GenericXMLParserTest {
* declaration
*/
encodedXML = ("<?xml version=\"1.0\"?>" + UMLAUT_TEXT_TAG).getBytes(StandardCharsets.UTF_8);
- testCharsetDetection(parser, encodedXML, "application/xml; charset=utf-8", StandardCharsets.UTF_8.name(),
+ testCharsetDetection(this.parser, encodedXML, "application/xml; charset=utf-8", StandardCharsets.UTF_8.name(),
"Maßkrügen");
}
@@ -169,7 +169,7 @@ public class GenericXMLParserTest {
*/
byte[] encodedXML = ("<?xml version=\"1.0\" encoding=\"utf-16\"?>" + UMLAUT_TEXT_TAG)
.getBytes(StandardCharsets.UTF_16);
- testCharsetDetection(parser, encodedXML, "application/xml; charset=utf-16", StandardCharsets.UTF_16.name(),
+ testCharsetDetection(this.parser, encodedXML, "application/xml; charset=utf-16", StandardCharsets.UTF_16.name(),
"Maßkrügen");
/*
@@ -177,7 +177,7 @@ public class GenericXMLParserTest {
* XML declaration having only BOM (Byte Order Mark)
*/
encodedXML = ("<?xml version=\"1.0\"?>" + UMLAUT_TEXT_TAG).getBytes(StandardCharsets.UTF_16);
- testCharsetDetection(parser, encodedXML, "application/xml; charset=utf-16",
+ testCharsetDetection(this.parser, encodedXML, "application/xml; charset=utf-16",
StandardCharsets.UTF_16BE.name(), "Maßkrügen");
/*
@@ -186,14 +186,14 @@ public class GenericXMLParserTest {
*/
encodedXML = ("<?xml version=\"1.0\" encoding=\"utf-16\"?>" + UMLAUT_TEXT_TAG)
.getBytes(StandardCharsets.UTF_16);
- testCharsetDetection(parser, encodedXML, "application/xml", StandardCharsets.UTF_16.name(), "Maßkrügen");
+ testCharsetDetection(this.parser, encodedXML, "application/xml", StandardCharsets.UTF_16.name(), "Maßkrügen");
/*
* Charset is omitted in both Content-Type HTTP header and XML
* declaration with BOM (Byte Order Mark)
*/
encodedXML = ("<?xml version=\"1.0\"?>" + UMLAUT_TEXT_TAG).getBytes(StandardCharsets.UTF_16);
- testCharsetDetection(parser, encodedXML, "application/xml", StandardCharsets.UTF_16BE.name(), "Maßkrügen");
+ testCharsetDetection(this.parser, encodedXML, "application/xml", StandardCharsets.UTF_16BE.name(), "Maßkrügen");
}
/**
@@ -211,9 +211,9 @@ public class GenericXMLParserTest {
* ISO-8859-1 charset provided only in XML declaration without BOM (Byte
* Order Mark)
*/
- byte[] encodedXML = ("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + UMLAUT_TEXT_TAG)
+ final byte[] encodedXML = ("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + UMLAUT_TEXT_TAG)
.getBytes(StandardCharsets.ISO_8859_1);
- testCharsetDetection(parser, encodedXML, "application/xml", StandardCharsets.ISO_8859_1.name(),
+ testCharsetDetection(this.parser, encodedXML, "application/xml", StandardCharsets.ISO_8859_1.name(),
"Maßkrügen");
}
@@ -234,7 +234,7 @@ public class GenericXMLParserTest {
* XML encoded as UTF-8 without BOM (Byte Order Mark)
*/
byte[] encodedXML = ("<?xml version=\"1.0\"?>" + UMLAUT_TEXT_TAG).getBytes(StandardCharsets.UTF_8);
- testCharsetDetection(parser, encodedXML, "application/xml", StandardCharsets.UTF_8.name(), "Maßkrügen");
+ testCharsetDetection(this.parser, encodedXML, "application/xml", StandardCharsets.UTF_8.name(), "Maßkrügen");
/*
* XML encoded as ASCII, with non ascii chars encoded as entities
@@ -242,7 +242,7 @@ public class GenericXMLParserTest {
encodedXML = ("<?xml version=\"1.0\"?>"
+ "<text>In M&#x000FC;nchen steht ein Hofbr&#x000E4;uhaus, dort gibt es Bier in Ma&#x000DF;kr&#x000FC;gen</text>")
.getBytes(StandardCharsets.US_ASCII);
- testCharsetDetection(parser, encodedXML, "application/xml", StandardCharsets.UTF_8.name(), "Maßkrügen");
+ testCharsetDetection(this.parser, encodedXML, "application/xml", StandardCharsets.UTF_8.name(), "Maßkrügen");
}
/**
@@ -260,9 +260,9 @@ public class GenericXMLParserTest {
* UTF-16BE charset provided both in Content-Type HTTP header and in XML
* declaration, without BOM (Byte Order Mark)
*/
- byte[] encodedXML = ("<?xml version='1.0' encoding='utf-16be'?>" + UMLAUT_TEXT_TAG)
+ final byte[] encodedXML = ("<?xml version='1.0' encoding='utf-16be'?>" + UMLAUT_TEXT_TAG)
.getBytes(StandardCharsets.UTF_16BE);
- testCharsetDetection(parser, encodedXML, "application/xml; charset=utf-16be",
+ testCharsetDetection(this.parser, encodedXML, "application/xml; charset=utf-16be",
StandardCharsets.UTF_16BE.name(), "Maßkrügen");
}
@@ -279,24 +279,24 @@ public class GenericXMLParserTest {
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head>"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
+ "<title>XHTML attributes URLs test</title>" + "</head>" + "<body>"
- + "Here are YaCy<a href=\"http://yacy.net\">home page</a> and <a href=\"https://searchlab.eu\">International Forum</a>."
+ + "Here are YaCy<a href=\"http://yacy.net\">home page</a> and <a href=\"https://community.searchlab.eu\">International Forum</a>."
+ "And this is a relative link to a <a href=\"/document.html\">sub document</a>." + "</body>"
+ "</html>";
- InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
+ final InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
final String contentTypeHeader = "text/xhtml";
- String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
- DigestURL location = new DigestURL("http://localhost/testfile.xml");
+ final String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
+ final DigestURL location = new DigestURL("http://localhost/testfile.xml");
try {
- Document[] documents = parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
+ final Document[] documents = this.parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
new VocabularyScraper(), 0, inStream);
assertEquals(1, documents.length);
- Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
+ final Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
assertNotNull(detectedAnchors);
assertEquals(3, detectedAnchors.size());
assertTrue(detectedAnchors.contains(new AnchorURL("http://www.w3.org/1999/xhtml")));
assertTrue(detectedAnchors.contains(new AnchorURL("http://yacy.net")));
- assertTrue(detectedAnchors.contains(new AnchorURL("https://searchlab.eu")));
+ assertTrue(detectedAnchors.contains(new AnchorURL("https://community.searchlab.eu")));
} finally {
inStream.close();
}
@@ -316,23 +316,23 @@ public class GenericXMLParserTest {
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
+ "<title>XHTML content URLs test</title>" + "</head>" + "<body>" + "Here are some YaCy links:" + "<dl>"
+ "<dt>Home page</dt>" + "<dd>http://yacy.net</dd>" + "<dt>International Forum</dt>"
- + "<dd>https://searchlab.eu</dd>" + "</dl>"
+ + "<dd>https://community.searchlab.eu</dd>" + "</dl>"
+ "And this is a mention to a relative link : /document.html " + "</body>" + "</html>";
- InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
+ final InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
final String contentTypeHeader = "text/xhtml";
- String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
- DigestURL location = new DigestURL("http://localhost/testfile.xml");
+ final String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
+ final DigestURL location = new DigestURL("http://localhost/testfile.xml");
try {
- Document[] documents = parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
+ final Document[] documents = this.parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
new VocabularyScraper(), 0, inStream);
assertEquals(1, documents.length);
- Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
+ final Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
assertNotNull(detectedAnchors);
assertEquals(3, detectedAnchors.size());
assertTrue(detectedAnchors.contains(new AnchorURL("http://www.w3.org/1999/xhtml")));
assertTrue(detectedAnchors.contains(new AnchorURL("http://yacy.net")));
- assertTrue(detectedAnchors.contains(new AnchorURL("https://searchlab.eu")));
+ assertTrue(detectedAnchors.contains(new AnchorURL("https://community.searchlab.eu")));
} finally {
inStream.close();
}
@@ -346,12 +346,12 @@ public class GenericXMLParserTest {
public void testParseXMLFragment() throws Exception {
final String xhtml = "<root><node><subNode1>Node content1</subNode1><subNode2>Node content2</subNode2></node></root>";
- InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
+ final InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
final String contentTypeHeader = "text/xml";
- String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
- DigestURL location = new DigestURL("http://localhost/testfile.xml");
+ final String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
+ final DigestURL location = new DigestURL("http://localhost/testfile.xml");
try {
- Document[] documents = parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
+ final Document[] documents = this.parser.parse(location, contentTypeHeader, charsetFromHttpHeader,
new VocabularyScraper(), 0, inStream);
assertEquals(1, documents.length);
assertEquals("Node content1 Node content2", documents[0].getTextString());
@@ -368,13 +368,13 @@ public class GenericXMLParserTest {
*/
@Test
public void testParseWithLimits() throws Exception {
- String xhtml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ final String xhtml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head>"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
+ "<title>XHTML content URLs test</title>" + "</head>" + "<body>" + "<p>Here are some YaCy URLs: "
+ "Home page : http://yacy.net - International Forum : "
- + "https://searchlab.eu "
+ + "https://community.searchlab.eu "
+ "and this is a mention to a relative URL : /document.html</p>"
+ "<p>Here are YaCy<a href=\"http://mantis.tokeek.de\">bug tracker</a> and <a href=\"https://wiki.yacy.net/index.php/\">Wiki</a>."
+ "And this is a relative link to another <a href=\"/document2.html\">sub document</a></p>"
@@ -383,21 +383,21 @@ public class GenericXMLParserTest {
/* Content within limits */
InputStream inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
final String contentTypeHeader = "text/xhtml";
- String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
- DigestURL location = new DigestURL("http://localhost/testfile.xml");
+ final String charsetFromHttpHeader = HeaderFramework.getCharacterEncoding(contentTypeHeader);
+ final DigestURL location = new DigestURL("http://localhost/testfile.xml");
try {
- Document[] documents = parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader, new VocabularyScraper(), 0, inStream, Integer.MAX_VALUE, Long.MAX_VALUE);
+ final Document[] documents = this.parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader, new VocabularyScraper(), 0, inStream, Integer.MAX_VALUE, Long.MAX_VALUE);
assertEquals(1, documents.length);
assertFalse(documents[0].isPartiallyParsed());
assertTrue(documents[0].getTextString().contains("And this is a relative link"));
- Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
+ final Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
assertNotNull(detectedAnchors);
assertEquals(5, detectedAnchors.size());
assertTrue(detectedAnchors.contains(new AnchorURL("http://www.w3.org/1999/xhtml")));
assertTrue(detectedAnchors.contains(new AnchorURL("http://yacy.net")));
- assertTrue(detectedAnchors.contains(new AnchorURL("https://searchlab.eu")));
+ assertTrue(detectedAnchors.contains(new AnchorURL("https://community.searchlab.eu")));
assertTrue(detectedAnchors.contains(new AnchorURL("http://mantis.tokeek.de")));
assertTrue(detectedAnchors.contains(new AnchorURL("https://wiki.yacy.net/index.php/")));
} finally {
@@ -407,7 +407,7 @@ public class GenericXMLParserTest {
/* Links limit exceeded */
inStream = new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8.name()));
try {
- Document[] documents = parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader,
+ final Document[] documents = this.parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader,
new VocabularyScraper(), 0, inStream, 2, Long.MAX_VALUE);
assertEquals(1, documents.length);
assertTrue(documents[0].isPartiallyParsed());
@@ -415,7 +415,7 @@ public class GenericXMLParserTest {
assertTrue(documents[0].getTextString().contains("Home page"));
assertFalse(documents[0].getTextString().contains("And this is a relative link"));
- Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
+ final Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
assertNotNull(detectedAnchors);
assertEquals(2, detectedAnchors.size());
assertTrue(detectedAnchors.contains(new AnchorURL("http://www.w3.org/1999/xhtml")));
@@ -425,7 +425,7 @@ public class GenericXMLParserTest {
}
/* Bytes limit exceeded */
- StringBuilder xhtmlBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
+ final StringBuilder xhtmlBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">")
.append("<head>")
@@ -434,7 +434,7 @@ public class GenericXMLParserTest {
.append("</head>")
.append("<body><p>Here are some YaCy URLs: ")
.append("Home page : http://yacy.net - International Forum : ")
- .append("https://searchlab.eu ")
+ .append("https://community.searchlab.eu ")
.append("and this is a mention to a relative URL : /document.html</p>");
/* Add some filler text to reach a total size beyond SAX parser internal input stream buffers */
@@ -442,25 +442,25 @@ public class GenericXMLParserTest {
xhtmlBuilder.append("<p>Some text to parse</p>");
}
- int firstBytes = xhtmlBuilder.toString().getBytes(StandardCharsets.UTF_8.name()).length;
+ final int firstBytes = xhtmlBuilder.toString().getBytes(StandardCharsets.UTF_8.name()).length;
xhtmlBuilder.append("<p>Here are YaCy<a href=\"http://mantis.tokeek.de\">bug tracker</a> and <a href=\"https://wiki.yacy.net/index.php/\">Wiki</a>.")
.append("And this is a relative link to another <a href=\"/document2.html\">sub document</a></p>")
.append("</body></html>");
inStream = new ByteArrayInputStream(xhtmlBuilder.toString().getBytes(StandardCharsets.UTF_8.name()));
try {
- Document[] documents = parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader, new VocabularyScraper(), 0, inStream, Integer.MAX_VALUE, firstBytes);
+ final Document[] documents = this.parser.parseWithLimits(location, contentTypeHeader, charsetFromHttpHeader, new VocabularyScraper(), 0, inStream, Integer.MAX_VALUE, firstBytes);
assertEquals(1, documents.length);
assertTrue(documents[0].isPartiallyParsed());
assertTrue(documents[0].getTextString().contains("and this is a mention to a relative URL"));
assertFalse(documents[0].getTextString().contains("And this is a relative link to another"));
- Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
+ final Collection<AnchorURL> detectedAnchors = documents[0].getAnchors();
assertNotNull(detectedAnchors);
assertEquals(3, detectedAnchors.size());
assertTrue(detectedAnchors.contains(new AnchorURL("http://www.w3.org/1999/xhtml")));
assertTrue(detectedAnchors.contains(new AnchorURL("http://yacy.net")));
- assertTrue(detectedAnchors.contains(new AnchorURL("https://searchlab.eu")));
+ assertTrue(detectedAnchors.contains(new AnchorURL("https://community.searchlab.eu")));
} finally {
inStream.close();
}
diff --git a/test/java/net/yacy/document/parser/html/ContentScraperTest.java b/test/java/net/yacy/document/parser/html/ContentScraperTest.java
index 105303166..cdb4f3951 100644
--- a/test/java/net/yacy/document/parser/html/ContentScraperTest.java
+++ b/test/java/net/yacy/document/parser/html/ContentScraperTest.java
@@ -143,13 +143,13 @@ public class ContentScraperTest {
@Test
public void testGetStartDates() throws MalformedURLException, IOException {
List<Date> dateResultList;
- DigestURL root = new DigestURL("http://test.org/test.html");
+ final DigestURL root = new DigestURL("http://test.org/test.html");
- String page = "<html><body>"
+ final String page = "<html><body>"
+ "<time datetime='2016-12-23'>23. Dezember 2016</time>" // html5 time tag
+ "</body></html>";
- ContentScraper scraper = new ContentScraper(root, 10, new HashSet<String>(), new VocabularyScraper(), 0);
+ final ContentScraper scraper = new ContentScraper(root, 10, new HashSet<String>(), new VocabularyScraper(), 0);
final Writer writer = new TransformerWriter(null, null, scraper, false);
FileUtils.copy(new StringReader(page), writer);
@@ -157,11 +157,11 @@ public class ContentScraperTest {
dateResultList = scraper.getStartDates();
- Calendar cal = Calendar.getInstance();
+ final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0); // to zero hours
cal.set(2016, Calendar.DECEMBER, 23);
- for (Date d : dateResultList) {
+ for (final Date d : dateResultList) {
Assert.assertEquals(cal.getTime(), d);
}
scraper.close();
@@ -173,35 +173,35 @@ public class ContentScraperTest {
*/
@Test
public void testFindAbsoluteURLs() throws MalformedURLException {
- final String[] urlStrings = { "http://yacy.net", "https://searchlab.eu", "https://en.wikipedia.org" };
+ final String[] urlStrings = { "http://yacy.net", "https://community.searchlab.eu", "https://en.wikipedia.org" };
final List<AnchorURL> urls = new ArrayList<>();
- for (String urlString : urlStrings) {
+ for (final String urlString : urlStrings) {
urls.add(new AnchorURL(urlString));
}
/* Test with various white space separators */
- String[] separators = { " ", "\n", "\t", "\r" };
- for (String separator : separators) {
- StringBuilder text = new StringBuilder();
- for (String urlString : urlStrings) {
+ final String[] separators = { " ", "\n", "\t", "\r" };
+ for (final String separator : separators) {
+ final StringBuilder text = new StringBuilder();
+ for (final String urlString : urlStrings) {
if (text.length() > 0) {
text.append(separator);
}
text.append(urlString);
}
- Collection<AnchorURL> detectedURLs = new ArrayList<>();
+ final Collection<AnchorURL> detectedURLs = new ArrayList<>();
ContentScraper.findAbsoluteURLs(text.toString(), detectedURLs, null);
Assert.assertEquals(urls.size(), detectedURLs.size());
Assert.assertTrue(urls.containsAll(detectedURLs));
}
/* URLs surrounded with parenthesis */
- String[] texts = { "(http://yacy.net)", "YaCy home page (http://yacy.net)",
+ final String[] texts = { "(http://yacy.net)", "YaCy home page (http://yacy.net)",
"Nested parentheses (YaCy home page (http://yacy.net))",
"Text in parenthesis (example : http://yacy.net)", "A markdown link [YaCy home page](http://yacy.net)",
"A markdown [example](http://yacy.net \"YaCy home page\") inline link" };
- for (String text : texts) {
- Collection<AnchorURL> detectedURLs = new ArrayList<>();
+ for (final String text : texts) {
+ final Collection<AnchorURL> detectedURLs = new ArrayList<>();
ContentScraper.findAbsoluteURLs(text, detectedURLs, null);
Assert.assertEquals(1, detectedURLs.size());
Assert.assertEquals(new AnchorURL("http://yacy.net"), detectedURLs.iterator().next());
@@ -209,11 +209,11 @@ public class ContentScraperTest {
/* URLs surrounded with square brackets */
//http://[abcd:ef01:2345:6789:abcd:ef01:2345:6789]/
- String[] squareBracketsTexts = { "[http://yacy.net]", "YaCy home page [http://yacy.net]",
+ final String[] squareBracketsTexts = { "[http://yacy.net]", "YaCy home page [http://yacy.net]",
"Nested brackets [YaCy home page [http://yacy.net]]",
"A mediawiki external link with different label [http://yacy.net YaCy home page]" };
- for(String text : squareBracketsTexts) {
- Collection<AnchorURL> detectedURLs = new ArrayList<>();
+ for(final String text : squareBracketsTexts) {
+ final Collection<AnchorURL> detectedURLs = new ArrayList<>();
ContentScraper.findAbsoluteURLs(text, detectedURLs, null);
Assert.assertEquals(1, detectedURLs.size());
Assert.assertEquals(new AnchorURL("http://yacy.net"), detectedURLs.iterator().next());
@@ -221,11 +221,11 @@ public class ContentScraperTest {
/* URLs surrounded with curly brackets */
//http://[abcd:ef01:2345:6789:abcd:ef01:2345:6789]/
- String[] curlyBracketsTexts = { "{http://yacy.net}", "YaCy home page {http://yacy.net}",
+ final String[] curlyBracketsTexts = { "{http://yacy.net}", "YaCy home page {http://yacy.net}",
"Nested brackets {YaCy home page {http://yacy.net}}",
"Text in brackets {example : http://yacy.net}" };
- for(String text : curlyBracketsTexts) {
- Collection<AnchorURL> detectedURLs = new ArrayList<>();
+ for(final String text : curlyBracketsTexts) {
+ final Collection<AnchorURL> detectedURLs = new ArrayList<>();
ContentScraper.findAbsoluteURLs(text, detectedURLs, null);
Assert.assertEquals(1, detectedURLs.size());
Assert.assertEquals(new AnchorURL("http://yacy.net"), detectedURLs.iterator().next());
@@ -277,7 +277,7 @@ public class ContentScraperTest {
*/
@Test
public void testFindAbsoluteURLsMaxURLs() throws MalformedURLException {
- final String text = "Some test URLS : http://yacy.net - https://searchlab.eu - https://en.wikipedia.org";
+ final String text = "Some test URLS : http://yacy.net - https://community.searchlab.eu - https://en.wikipedia.org";
/* No limit */
ArrayList<AnchorURL> detectedURLs = new ArrayList<>();
@@ -425,7 +425,7 @@ public class ContentScraperTest {
html2Results.put(html, expectedUrls);
for (final Entry<String, String[]> html2Result : html2Results.entrySet()) {
- ContentScraper scraper = new ContentScraper(docUrl, 10, new HashSet<String>(), new VocabularyScraper(), 0);
+ final ContentScraper scraper = new ContentScraper(docUrl, 10, new HashSet<String>(), new VocabularyScraper(), 0);
try (final Writer writer = new TransformerWriter(null, null, scraper, false)) {
FileUtils.copy(new StringReader(html2Result.getKey()), writer);
@@ -500,7 +500,7 @@ public class ContentScraperTest {
for (final Entry<String, String[]> html2Result : html2Results.entrySet()) {
- ContentScraper scraper = new ContentScraper(docUrl, 10, new HashSet<String>(), new VocabularyScraper(), 0);
+ final ContentScraper scraper = new ContentScraper(docUrl, 10, new HashSet<String>(), new VocabularyScraper(), 0);
try (final Writer writer = new TransformerWriter(null, null, scraper, false)) {
FileUtils.copy(new StringReader(html2Result.getKey()), writer);
diff --git a/test/java/net/yacy/document/parser/ooxmlParserTest.java b/test/java/net/yacy/document/parser/ooxmlParserTest.java
index f5cf79e47..12d30dee2 100644
--- a/test/java/net/yacy/document/parser/ooxmlParserTest.java
+++ b/test/java/net/yacy/document/parser/ooxmlParserTest.java
@@ -93,7 +93,7 @@ public class ooxmlParserTest {
final String mimetype = testFile[1];
final AnchorURL url = new AnchorURL("http://localhost/" + filename);
- AbstractParser p = new ooxmlParser();
+ final AbstractParser p = new ooxmlParser();
inStream = new FileInputStream(file);
final Document[] docs = p.parse(url, mimetype, null, new VocabularyScraper(), 0, inStream);
for (final Document doc : docs) {
@@ -116,7 +116,7 @@ public class ooxmlParserTest {
if (content != null) {
try {
content.close();
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
System.out.println("Could not close text input stream");
}
}
@@ -126,7 +126,7 @@ public class ooxmlParserTest {
if (inStream != null) {
try {
inStream.close();
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
System.out.println("Could not close input stream on file " + filename);
}
}
@@ -145,7 +145,7 @@ public class ooxmlParserTest {
final String mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
final AnchorURL url = new AnchorURL("http://localhost/" + fileName);
- AbstractParser p = new ooxmlParser();
+ final AbstractParser p = new ooxmlParser();
try(InputStream inStream = new FileInputStream(file);) {
final Document[] docs = p.parse(url, mimetype, null, new VocabularyScraper(), 0, inStream);
assertNotNull("Documents result must not be null", docs);
@@ -153,7 +153,7 @@ public class ooxmlParserTest {
assertNotNull("Detected URLs must not be null", anchors);
assertEquals("2 URLs should be detected", 2, anchors.size());
assertTrue("YaCy home page URL should have been parsed: " + anchors.toString(), anchors.contains(new AnchorURL("http://yacy.net/")));
- assertTrue("YaCy forum URL should have been parsed: " + anchors.toString(), anchors.contains(new AnchorURL("https://searchlab.eu/")));
+ assertTrue("YaCy forum URL should have been parsed: " + anchors.toString(), anchors.contains(new AnchorURL("https://community.searchlab.eu/")));
}
}