1
1
package com .github .bazel_contrib .contrib_rules_jvm .junit5 ;
2
2
3
- import org .junit .jupiter .api .Test ;
4
- import org .w3c .dom .Document ;
5
- import org .w3c .dom .Node ;
6
- import org .xml .sax .InputSource ;
7
- import org .xml .sax .SAXException ;
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
8
4
5
+ import java .io .IOException ;
6
+ import java .io .Reader ;
7
+ import java .io .StringReader ;
8
+ import java .io .StringWriter ;
9
+ import java .io .Writer ;
9
10
import javax .xml .parsers .DocumentBuilder ;
10
11
import javax .xml .parsers .DocumentBuilderFactory ;
11
12
import javax .xml .parsers .ParserConfigurationException ;
12
13
import javax .xml .stream .XMLOutputFactory ;
13
14
import javax .xml .stream .XMLStreamException ;
14
15
import javax .xml .stream .XMLStreamWriter ;
15
- import java .io .IOException ;
16
- import java .io .Reader ;
17
- import java .io .StringReader ;
18
- import java .io .StringWriter ;
19
- import java .io .Writer ;
20
-
21
- import static org .junit .jupiter .api .Assertions .assertEquals ;
16
+ import org .junit .jupiter .api .Test ;
17
+ import org .w3c .dom .Document ;
18
+ import org .w3c .dom .Node ;
19
+ import org .xml .sax .InputSource ;
20
+ import org .xml .sax .SAXException ;
22
21
23
22
public class SafeXmlTest {
24
23
25
- @ Test
26
- public void properlyEscapesCDataSection ()
27
- throws XMLStreamException , ParserConfigurationException , IOException , SAXException {
28
- try (Writer writer = new StringWriter ()) {
29
- XMLStreamWriter xml = XMLOutputFactory .newDefaultFactory ().createXMLStreamWriter (writer );
24
+ @ Test
25
+ public void properlyEscapesCDataSection ()
26
+ throws XMLStreamException , ParserConfigurationException , IOException , SAXException {
27
+ try (Writer writer = new StringWriter ()) {
28
+ XMLStreamWriter xml = XMLOutputFactory .newDefaultFactory ().createXMLStreamWriter (writer );
30
29
31
- xml .writeStartDocument ("UTF-8" , "1.0" );
32
- // Output the "end of cdata" marker
33
- SafeXml .writeTextElement (xml , "container" , "]]>" );
34
- xml .writeEndDocument ();
30
+ xml .writeStartDocument ("UTF-8" , "1.0" );
31
+ // Output the "end of cdata" marker
32
+ SafeXml .writeTextElement (xml , "container" , "]]>" );
33
+ xml .writeEndDocument ();
35
34
36
- DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
37
- DocumentBuilder builder ;
38
- try (Reader reader = new StringReader (writer .toString ())) {
39
- builder = factory .newDocumentBuilder ();
40
- Document parsed = builder .parse (new InputSource (reader ));
35
+ DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
36
+ DocumentBuilder builder ;
37
+ try (Reader reader = new StringReader (writer .toString ())) {
38
+ builder = factory .newDocumentBuilder ();
39
+ Document parsed = builder .parse (new InputSource (reader ));
41
40
42
- Node container = parsed .getElementsByTagName ("container" ).item (0 );
41
+ Node container = parsed .getElementsByTagName ("container" ).item (0 );
43
42
44
- assertEquals ("]]>" , container .getTextContent ());
45
- }
46
- }
43
+ assertEquals ("]]>" , container .getTextContent ());
44
+ }
47
45
}
48
- }
46
+ }
47
+ }
0 commit comments