/
CommentTest.java
66 lines (54 loc) · 2.1 KB
/
CommentTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.jsoup.nodes;
import org.jsoup.Jsoup;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CommentTest {
private Comment comment = new Comment(" This is one heck of a comment! ");
private Comment decl = new Comment("?xml encoding='ISO-8859-1'?");
@Test
public void nodeName() {
assertEquals("#comment", comment.nodeName());
}
@Test
public void getData() {
assertEquals(" This is one heck of a comment! ", comment.getData());
}
@Test
public void testToString() {
// Tests under toString are pretty printed with first being simulated license header (no content), respect new line
assertEquals("<!-- This is one heck of a comment! -->\n", comment.toString());
Document doc = Jsoup.parse("<div><!-- comment--></div>");
assertEquals("<div>\n <!-- comment-->\n</div>", doc.body().html());
doc = Jsoup.parse("<p>One<!-- comment -->Two</p>");
assertEquals("<p>One<!-- comment -->Two</p>", doc.body().html());
assertEquals("OneTwo", doc.text());
}
@Test
public void testHtmlNoPretty() {
Document doc = Jsoup.parse("<!-- a simple comment -->");
doc.outputSettings().prettyPrint(false);
assertEquals("<!-- a simple comment --><html><head></head><body></body></html>", doc.html());
Node node = doc.childNode(0);
Comment c1 = (Comment) node;
assertEquals("<!-- a simple comment -->", c1.outerHtml());
}
@Test
public void testClone() {
Comment c1 = comment.clone();
assertNotSame(comment, c1);
assertEquals(comment.getData(), comment.getData());
c1.setData("New");
assertEquals("New", c1.getData());
assertNotEquals(c1.getData(), comment.getData());
}
@Test
public void isXmlDeclaration() {
assertFalse(comment.isXmlDeclaration());
assertTrue(decl.isXmlDeclaration());
}
@Test
public void asXmlDeclaration() {
XmlDeclaration xmlDeclaration = decl.asXmlDeclaration();
assertNotNull(xmlDeclaration);
}
}