JDK 8 build fix: now test uses LinkedHashMap to avoid random position of attributes in XML.

This commit is contained in:
Simone Bordet 2014-03-20 15:26:09 +01:00
parent a3ae739ca3
commit 48c803b693
1 changed files with 33 additions and 17 deletions

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.xml;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
@ -31,24 +31,40 @@ public class XmlAppendableTest
{
StringBuilder b = new StringBuilder();
XmlAppendable out = new XmlAppendable(b);
Map<String,String> attr = new HashMap<>();
Map<String, String> attr = new LinkedHashMap<>();
out.open("test");
attr.put("name","attr value");
attr.put("noval",null);
attr.put("quotes","'\"");
attr.put("name", "attr value");
attr.put("noval", null);
attr.put("quotes", "'\"");
out.tag("tag");
out.tag("tag",attr);
out.tag("tag",attr,"content");
out.open("level1").tag("tag","content").tag("tag","content").close();
out.open("level1",attr).open("level2").tag("tag","content").tag("tag","content").close().close();
out.tag("tag", attr);
out.tag("tag", attr, "content");
out.open("level1").tag("tag", "content").tag("tag", "content").close();
out.open("level1", attr).open("level2").tag("tag", "content").tag("tag", "content").close().close();
out.close();
String s = b.toString();
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test>\n <tag/>\n <tag quotes=\"&apos;&quot;\" name=\"attr value\" noval=\"\"/>\n <tag quotes=\"&apos;&quot;\" name=\"attr value\" noval=\"\">content</tag>\n <level1>\n <tag>content</tag>\n <tag>content</tag>\n </level1>\n <level1 quotes=\"&apos;&quot;\" name=\"attr value\" noval=\"\">\n <level2>\n <tag>content</tag>\n <tag>content</tag>\n </level2>\n </level1>\n</test>\n",s);
String expected = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<test>\n" +
" <tag/>\n" +
" <tag name=\"attr value\" noval=\"\" quotes=\"&apos;&quot;\"/>\n" +
" <tag name=\"attr value\" noval=\"\" quotes=\"&apos;&quot;\">content</tag>\n" +
" <level1>\n" +
" <tag>content</tag>\n" +
" <tag>content</tag>\n" +
" </level1>\n" +
" <level1 name=\"attr value\" noval=\"\" quotes=\"&apos;&quot;\">\n" +
" <level2>\n" +
" <tag>content</tag>\n" +
" <tag>content</tag>\n" +
" </level2>\n" +
" </level1>\n" +
"</test>\n";
Assert.assertEquals(expected, b.toString());
}
}