@@ -14,14 +14,15 @@ public class XmlGeneratorInitializerTest extends XmlTestUtil
1414{
1515 private final XmlMapper MAPPER = newMapper ();
1616
17- // [dataformat-xml#150]: DTD writing -- ok cases
17+ // // [dataformat-xml#150]: DTD writing -- ok cases
18+
1819 @ Test
1920 public void testDTDWithOnlyRootElement () throws Exception
2021 {
2122 ObjectWriter w = MAPPER .writer ().with (
2223 new XmlGeneratorInitializer ()
2324 .addDTD ("StringBean" , null , null , null ));
24- assertEquals (a2q ("<!DOCTYPE StringBean>"
25+ assertEquals (a2q ("<!DOCTYPE StringBean>\n "
2526 +"<StringBean><text>test</text></StringBean>" ),
2627 w .writeValueAsString (new StringBean ("test" )));
2728 }
@@ -32,7 +33,7 @@ public void testDTDWithPublicId() throws Exception
3233 ObjectWriter w = MAPPER .writer ().with (
3334 new XmlGeneratorInitializer ()
3435 .addDTD ("StringBean" , "system" , "http://foo.bar" , "" ));
35- assertEquals (a2q ("<!DOCTYPE StringBean PUBLIC 'http://foo.bar' 'system'>"
36+ assertEquals (a2q ("<!DOCTYPE StringBean PUBLIC 'http://foo.bar' 'system'>\n "
3637 +"<StringBean><text>test</text></StringBean>" ),
3738 w .writeValueAsString (new StringBean ("test" )));
3839 }
@@ -43,7 +44,7 @@ public void testDTDWithSystemIdOnly() throws Exception
4344 ObjectWriter w = MAPPER .writer ().with (
4445 new XmlGeneratorInitializer ()
4546 .addDTD ("StringBean" , "system" , "" , null ));
46- assertEquals (a2q ("<!DOCTYPE StringBean SYSTEM 'system'>"
47+ assertEquals (a2q ("<!DOCTYPE StringBean SYSTEM 'system'>\n "
4748 +"<StringBean><text>test</text></StringBean>" ),
4849 w .writeValueAsString (new StringBean ("test" )));
4950 }
@@ -55,7 +56,7 @@ public void testDTDWithInternalSubset() throws Exception
5556 new XmlGeneratorInitializer ()
5657 .addDTD ("StringBean" , "system" , "http://foo.bar" , "<!ELEMENT root (#PCDATA)>" ));
5758 assertEquals (a2q ("<!DOCTYPE StringBean PUBLIC 'http://foo.bar' 'system' "
58- +"[<!ELEMENT root (#PCDATA)>]>"
59+ +"[<!ELEMENT root (#PCDATA)>]>\n "
5960 +"<StringBean><text>test</text></StringBean>" ),
6061 w .writeValueAsString (new StringBean ("test" )));
6162 }
@@ -72,13 +73,13 @@ public void testDTDWithXmlDeclaration() throws Exception
7273 .addDTD ("StringBean" , "system" , "http://foo.bar" , null ));
7374 // XML declaration is emitted with single quotes, DOCTYPE with double quotes,
7475 // so cannot use a2q() on the whole string here.
75- assertEquals ("<?xml version='1.0' encoding='UTF-8'?>"
76- +"<!DOCTYPE StringBean PUBLIC \" http://foo.bar\" \" system\" >"
76+ assertEquals ("<?xml version='1.0' encoding='UTF-8'?>\n "
77+ +"<!DOCTYPE StringBean PUBLIC \" http://foo.bar\" \" system\" >\n "
7778 +"<StringBean><text>test</text></StringBean>" ,
7879 w .writeValueAsString (new StringBean ("test" )));
7980 }
8081
81- // [dataformat-xml#150]: DTD writing -- failing cases
82+ // // [dataformat-xml#150]: DTD writing -- failing cases
8283 @ Test
8384 public void testDTDInvalidNoRoot () throws Exception
8485 {
@@ -92,5 +93,18 @@ public void testDTDInvalidNoRoot() throws Exception
9293 }
9394 }
9495
95- // Other tests
96+ // // [dataformat-xml#849]: Comment writing -- ok cases
97+
98+ @ Test
99+ public void testSimpleComment () throws Exception
100+ {
101+ ObjectWriter w = MAPPER .writer ().with (
102+ new XmlGeneratorInitializer ()
103+ .addComment ("Comment content!" ));
104+ assertEquals (a2q ("<!--Comment content!-->\n "
105+ +"<StringBean><text>test</text></StringBean>" ),
106+ w .writeValueAsString (new StringBean ("test" )));
107+ }
108+
109+ // // Other tests
96110}
0 commit comments