On Oct 28, 2008, at 11:07 AM, Sergiu Dumitriu wrote:
vmassol (SVN) wrote:
Author: vmassol Date: 2008-10-28 09:19:23 +0100 (Tue, 28 Oct 2008) New Revision: 13864
Added: platform/core/trunk/xwiki-rendering/src/test/java/org/xwiki/ rendering/block/XMLBlockTest.java Modified: platform/core/trunk/xwiki-rendering/src/main/java/org/xwiki/ rendering/block/XMLBlock.java Log: XWIKI-2785: The order in which XML attributes are printed when converted to XWiki syntax is not fixed
+ public void testAttributeOrder() + { + Map<String, String> attributes = new HashMap<String, String>(); + attributes.put("aaa", "value1"); + attributes.put("bbb", "value2"); + XMLBlock block = new XMLBlock("element", attributes); + + Iterator<String> it = attributes.keySet().iterator(); + Iterator<String> newIt = block.getAttributes().keySet().iterator(); + while (it.hasNext()) { + assertEquals(newIt.next(), it.next()); + } + }
I'm not sure this test is enough,
it's definitely not enough.
since the order for two attributes could happen to be the same. Why not add 10 attributes (aN = vN, where N goes from 0 to 9)?
I've just tried this: public void testAttributeOrder() { Map<String, String> attributes = new HashMap<String, String>(); for (int i = 0; i < 10; i++) { attributes.put("key" + i, "value" + i); } XMLBlock block = new XMLBlock("element", attributes); Iterator<String> it = attributes.keySet().iterator(); Iterator<String> newIt = block.getAttributes().keySet().iterator(); while (it.hasNext()) { assertEquals(newIt.next(), it.next()); } } And the tests till passes even when I revert the implementation for XMLBlock (i.e. no usage of LinkedHashMap). Any more idea? Could it be that the test is wrong or the implementation not correct? (I don't se anything wrong). Thanks -Vincent