Search in sources :

Example 1 with ENewLineMode

use of com.helger.commons.system.ENewLineMode in project ph-commons by phax.

the class XMLWriterSettingsTest method testPermutations.

@Test
@Ignore("Tested and works but takes too long")
public void testPermutations() {
    // Now try all permutations
    final XMLWriterSettings aXWS = new XMLWriterSettings();
    for (final EXMLSerializeXMLDeclaration eXMLDecl : EXMLSerializeXMLDeclaration.values()) {
        aXWS.setSerializeXMLDeclaration(eXMLDecl);
        assertEquals(eXMLDecl, aXWS.getSerializeXMLDeclaration());
        for (final EXMLSerializeDocType eDocType : EXMLSerializeDocType.values()) {
            aXWS.setSerializeDocType(eDocType);
            assertEquals(eDocType, aXWS.getSerializeDocType());
            for (final boolean bNewLineAfterXMLDecl : BOOLS) {
                aXWS.setNewLineAfterXMLDeclaration(bNewLineAfterXMLDecl);
                CommonsAssert.assertEquals(bNewLineAfterXMLDecl, aXWS.isNewLineAfterXMLDeclaration());
                for (final EXMLSerializeComments eComments : EXMLSerializeComments.values()) {
                    aXWS.setSerializeComments(eComments);
                    assertEquals(eComments, aXWS.getSerializeComments());
                    for (final EXMLSerializeIndent eIndent : EXMLSerializeIndent.values()) {
                        aXWS.setIndent(eIndent);
                        assertEquals(eIndent, aXWS.getIndent());
                        for (final EXMLIncorrectCharacterHandling eIncorrectCharHandling : EXMLIncorrectCharacterHandling.values()) {
                            aXWS.setIncorrectCharacterHandling(eIncorrectCharHandling);
                            assertEquals(eIncorrectCharHandling, aXWS.getIncorrectCharacterHandling());
                            for (final Charset aCS : CharsetHelper.getAllCharsets().values()) {
                                aXWS.setCharset(aCS);
                                assertEquals(aCS, aXWS.getCharset());
                                assertEquals(aCS.name(), aXWS.getCharset().name());
                                for (final boolean bUseDoubleQuotesForAttributes : BOOLS) {
                                    aXWS.setUseDoubleQuotesForAttributes(bUseDoubleQuotesForAttributes);
                                    CommonsAssert.assertEquals(bUseDoubleQuotesForAttributes, aXWS.isUseDoubleQuotesForAttributes());
                                    for (final boolean bSpaceOnSelfClosedElement : BOOLS) {
                                        aXWS.setSpaceOnSelfClosedElement(bSpaceOnSelfClosedElement);
                                        CommonsAssert.assertEquals(bSpaceOnSelfClosedElement, aXWS.isSpaceOnSelfClosedElement());
                                        for (final ENewLineMode eNewlineMode : ENewLineMode.values()) {
                                            aXWS.setNewLineMode(eNewlineMode);
                                            assertEquals(eNewlineMode, aXWS.getNewLineMode());
                                            assertTrue(StringHelper.hasText(aXWS.getNewLineString()));
                                            for (final String sIndentation : new String[] { "\t", "  " }) {
                                                aXWS.setIndentationString(sIndentation);
                                                assertEquals(sIndentation, aXWS.getIndentationString());
                                                for (final boolean bEmitNamespaces : BOOLS) {
                                                    aXWS.setEmitNamespaces(bEmitNamespaces);
                                                    CommonsAssert.assertEquals(bEmitNamespaces, aXWS.isEmitNamespaces());
                                                    for (final boolean bPutNamespaceContextPrefixesInRoot : BOOLS) {
                                                        aXWS.setPutNamespaceContextPrefixesInRoot(bPutNamespaceContextPrefixesInRoot);
                                                        CommonsAssert.assertEquals(bPutNamespaceContextPrefixesInRoot, aXWS.isPutNamespaceContextPrefixesInRoot());
                                                        final XMLWriterSettings aXWS2 = new XMLWriterSettings().setSerializeXMLDeclaration(eXMLDecl).setSerializeDocType(eDocType).setSerializeComments(eComments).setIndent(eIndent).setIncorrectCharacterHandling(eIncorrectCharHandling).setCharset(aCS).setUseDoubleQuotesForAttributes(bUseDoubleQuotesForAttributes).setSpaceOnSelfClosedElement(bSpaceOnSelfClosedElement).setNewLineMode(eNewlineMode).setIndentationString(sIndentation).setEmitNamespaces(bEmitNamespaces).setPutNamespaceContextPrefixesInRoot(bPutNamespaceContextPrefixesInRoot);
                                                        CommonsTestHelper.testEqualsImplementationWithEqualContentObject(aXWS, aXWS2);
                                                        CommonsTestHelper.testHashcodeImplementationWithEqualContentObject(aXWS, aXWS2);
                                                    // Main time is spent in the "toString" calls - so
                                                    // don't test it in the loop
                                                    }
                                                    CommonsAssert.assertEquals(bEmitNamespaces, aXWS.isEmitNamespaces());
                                                }
                                                assertEquals(sIndentation, aXWS.getIndentationString());
                                            }
                                            assertEquals(eNewlineMode, aXWS.getNewLineMode());
                                        }
                                        CommonsAssert.assertEquals(bSpaceOnSelfClosedElement, aXWS.isSpaceOnSelfClosedElement());
                                    }
                                    CommonsAssert.assertEquals(bUseDoubleQuotesForAttributes, aXWS.isUseDoubleQuotesForAttributes());
                                }
                                assertEquals(aCS, aXWS.getCharset());
                                assertEquals(aCS.name(), aXWS.getCharset().name());
                            }
                            assertEquals(eIncorrectCharHandling, aXWS.getIncorrectCharacterHandling());
                        }
                        assertEquals(eIndent, aXWS.getIndent());
                    }
                    assertEquals(eComments, aXWS.getSerializeComments());
                }
                CommonsAssert.assertEquals(bNewLineAfterXMLDecl, aXWS.isNewLineAfterXMLDeclaration());
            }
            assertEquals(eDocType, aXWS.getSerializeDocType());
        }
        assertEquals(eXMLDecl, aXWS.getSerializeXMLDeclaration());
    }
}
Also used : Charset(java.nio.charset.Charset) ENewLineMode(com.helger.commons.system.ENewLineMode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ENewLineMode (com.helger.commons.system.ENewLineMode)1 Charset (java.nio.charset.Charset)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1