Skip to content

Commit

Permalink
checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 21, 2024
1 parent 7689001 commit 9a4b524
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
44 changes: 24 additions & 20 deletions src/test/java/org/htmlunit/cyberneko/HTMLScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void evaluateInputSource() throws Exception {
final String[] expectedString = {"(html", "(head", "(title", ")title", ")head", "(body", "(script",
")script", "~inserting", "(style", "~inserting", "~inserting", ")style", "~inserting",
"(div", "(span", ")span", "~inserting", ")div", "(div", "(a", ")a", ")div", ")body", ")html"};
assertEquals(Arrays.asList(expectedString), filter.collectedStrings_);
assertEquals(Arrays.asList(expectedString), filter.getCollectedStrings());
}

/**
Expand All @@ -103,7 +103,7 @@ public void locale() throws Exception {
parser.parse(source);

final String[] expectedString = {"(html", "(head", "(title", ")title", ")head", "(body", ")body", ")html"};
assertEquals(Arrays.asList(expectedString).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expectedString).toString(), filter.getCollectedStrings().toString());
}
finally {
Locale.setDefault(originalLocale);
Expand All @@ -129,7 +129,7 @@ private static class EvaluateInputSourceFilter extends DefaultFilter {

private static int Counter_ = 1;

final List<String> collectedStrings_ = new ArrayList<>();
private final List<String> collectedStrings_ = new ArrayList<>();
private final HTMLConfiguration configuration_;

EvaluateInputSourceFilter(final HTMLConfiguration config) {
Expand All @@ -154,6 +154,10 @@ public void endElement(final QName element, final Augmentations augs) throws XNI
}
}

public List<String> getCollectedStrings() {
return collectedStrings_;
}

private void insert(final String string) {
collectedStrings_.add("~inserting");
final XMLInputSource source = new XMLInputSource(null, "myTest" + Counter_++, null,
Expand Down Expand Up @@ -218,7 +222,7 @@ public void elementNameNormalization() throws Exception {
parser.parse(source);

final String[] expectedString = {"(HTML", "(Head", "(tiTLE", ")tiTLE", ")Head", "(Body", ")Body", ")HTML"};
assertEquals(Arrays.asList(expectedString).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expectedString).toString(), filter.getCollectedStrings().toString());

// upper
parser = new HTMLConfiguration();
Expand All @@ -229,7 +233,7 @@ public void elementNameNormalization() throws Exception {
parser.parse(source);

final String[] expectedStringUpper = {"(HTML", "(HEAD", "(TITLE", ")TITLE", ")HEAD", "(BODY", ")BODY", ")HTML"};
assertEquals(Arrays.asList(expectedStringUpper).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expectedStringUpper).toString(), filter.getCollectedStrings().toString());

// upper
parser = new HTMLConfiguration();
Expand All @@ -240,7 +244,7 @@ public void elementNameNormalization() throws Exception {
parser.parse(source);

final String[] expectedStringLower = {"(html", "(head", "(title", ")title", ")head", "(body", ")body", ")html"};
assertEquals(Arrays.asList(expectedStringLower).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expectedStringLower).toString(), filter.getCollectedStrings().toString());
}

/**
Expand All @@ -258,7 +262,7 @@ public void invalidProcessingInstruction() throws Exception {
parser.parse(source);

final String[] expected = {"(HTML", "(head", ")head", "(body", ")body", ")html"};
assertEquals(Arrays.asList(expected).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expected).toString(), filter.getCollectedStrings().toString());
}

/**
Expand All @@ -276,7 +280,7 @@ public void invalidProcessingInstruction2() throws Exception {
parser.parse(source);

final String[] expected = {"(HTML", "(head", ")head", "(body", ")body", ")html"};
assertEquals(Arrays.asList(expected).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expected).toString(), filter.getCollectedStrings().toString());
}

/**
Expand All @@ -294,7 +298,7 @@ public void invalidProcessingInstruction3() throws Exception {
parser.parse(source);

final String[] expected = {"(HTML", "(head", ")head", "(body", ")body", ")html"};
assertEquals(Arrays.asList(expected).toString(), filter.collectedStrings_.toString());
assertEquals(Arrays.asList(expected).toString(), filter.getCollectedStrings().toString());
}

/**
Expand All @@ -308,17 +312,17 @@ public void reader() throws Exception {
+ "</body></html>";

final String[] expected = {
"(html",
"(head",
")head",
"(body",
"(script",
"Atype text/javascript",
"\"//<!-- /* <![CDATA[ */ function foo() {} /* ]]> */ // --> ",
")script",
")body",
")html"
};
"(html",
"(head",
")head",
"(body",
"(script",
"Atype text/javascript",
"\"//<!-- /* <![CDATA[ */ function foo() {} /* ]]> */ // --> ",
")script",
")body",
")html"
};

try (StringWriter out = new StringWriter()) {
final HTMLConfiguration parser = new HTMLConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void ignoredTags() throws Exception {
"end div", "ignored end form",
"end body", "end html"};

assertEquals(Arrays.asList(expectedMessages).toString(), parser.messages_.toString());
assertEquals(Arrays.asList(expectedMessages).toString(), parser.getMessages().toString());
}

/**
Expand All @@ -81,15 +81,15 @@ public void reuse() throws Exception {
final String[] expectedMessages = {"start HTML", "start head", "start title", "end title", "end head",
"start body", "start div", "end div", "end body", "end HTML"};

assertEquals(Arrays.asList(expectedMessages).toString(), parser.messages_.toString());
assertEquals(Arrays.asList(expectedMessages).toString(), parser.getMessages().toString());

parser.messages_.clear();
parser.getMessages().clear();
parser.parse(new XMLInputSource(null, "foo", null, new StringReader(string), null));
assertEquals(Arrays.asList(expectedMessages).toString(), parser.messages_.toString());
assertEquals(Arrays.asList(expectedMessages).toString(), parser.getMessages().toString());
}

private static final class TestParser extends AbstractSAXParser implements HTMLTagBalancingListener {
final List<String> messages_ = new ArrayList<>();
private final List<String> messages_ = new ArrayList<>();

TestParser() throws Exception {
super(new HTMLConfiguration());
Expand Down Expand Up @@ -118,5 +118,9 @@ public void endElement(final QName element, final Augmentations augs) throws XNI
messages_.add("end " + element.getRawname());
super.endElement(element, augs);
}

public List<String> getMessages() {
return messages_;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void guess() throws SAXException, IOException {
static final class TestContentHandler implements ContentHandler {
private final Locator[] locators_;

public TestContentHandler(final Locator[] locators) {
TestContentHandler(final Locator[] locators) {
locators_ = locators;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void detectEncodingUtf16LE() throws Exception {
*/
@Test
public void detectEncodingUtf16LEPart() throws Exception {
final byte[] bytes = new byte[] {(byte) 0xff,(byte) 0x20};
final byte[] bytes = new byte[] {(byte) 0xff, (byte) 0x20};

try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
PlaybackInputStream pbis = new PlaybackInputStream(bais)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public void tagName() throws Exception {
+ "<DIv>abc</DIv>"
+ "</bodY></HTML>";

DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
parser.parse(new InputSource(new StringReader(html)));
Document doc = parser.getDocument();
final Document doc = parser.getDocument();

Element htmlElem = doc.getDocumentElement();
final Element htmlElem = doc.getDocumentElement();
assertEquals("HTML", htmlElem.getTagName());

Element headElem = (Element) htmlElem.getChildNodes().item(0);
final Element headElem = (Element) htmlElem.getChildNodes().item(0);
assertEquals("head", headElem.getTagName());

Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
final Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
assertEquals("bODy", bodyElem.getTagName());

Element divElem = (Element) bodyElem.getChildNodes().item(0);
final Element divElem = (Element) bodyElem.getChildNodes().item(0);
assertEquals("DIv", divElem.getTagName());

assertEquals(bodyElem, doc.getElementsByTagName("bODy").item(0));
Expand All @@ -74,22 +74,22 @@ public void tagNameLower() throws Exception {
+ "<DIv>abc</DIv>"
+ "</bodY></HTML>";

DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");

parser.parse(new InputSource(new StringReader(html)));
Document doc = parser.getDocument();
final Document doc = parser.getDocument();

Element htmlElem = doc.getDocumentElement();
final Element htmlElem = doc.getDocumentElement();
assertEquals("html", htmlElem.getTagName());

Element headElem = (Element) htmlElem.getChildNodes().item(0);
final Element headElem = (Element) htmlElem.getChildNodes().item(0);
assertEquals("head", headElem.getTagName());

Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
final Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
assertEquals("body", bodyElem.getTagName());

Element divElem = (Element) bodyElem.getChildNodes().item(0);
final Element divElem = (Element) bodyElem.getChildNodes().item(0);
assertEquals("div", divElem.getTagName());

assertEquals(bodyElem, doc.getElementsByTagName("bODy").item(0));
Expand All @@ -110,22 +110,22 @@ public void tagNameUpper() throws Exception {
+ "<DIv>abc</DIv>"
+ "</bodY></HTML>";

DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "upper");

parser.parse(new InputSource(new StringReader(html)));
Document doc = parser.getDocument();
final Document doc = parser.getDocument();

Element htmlElem = doc.getDocumentElement();
final Element htmlElem = doc.getDocumentElement();
assertEquals("HTML", htmlElem.getTagName());

Element headElem = (Element) htmlElem.getChildNodes().item(0);
final Element headElem = (Element) htmlElem.getChildNodes().item(0);
assertEquals("HEAD", headElem.getTagName());

Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
final Element bodyElem = (Element) htmlElem.getChildNodes().item(1);
assertEquals("BODY", bodyElem.getTagName());

Element divElem = (Element) bodyElem.getChildNodes().item(0);
final Element divElem = (Element) bodyElem.getChildNodes().item(0);
assertEquals("DIV", divElem.getTagName());

assertEquals(bodyElem, doc.getElementsByTagName("bODy").item(0));
Expand Down

0 comments on commit 9a4b524

Please sign in to comment.