Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: indentify the bug with XMLDocument comparison #247

Merged
merged 8 commits into from
May 24, 2024
Prev Previous commit
bug(#247): fix all qulice suggestions
  • Loading branch information
volodya-lombrozo committed May 6, 2024
commit 475c890121caf645a5111eec653d0c955e436c41
14 changes: 12 additions & 2 deletions src/main/java/com/jcabi/xml/XMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public final class XMLDocument implements XML {
*/
private final transient Node cache;

/**
* Transformer factory to use for {@link #toString()}.
*/
private final transient TransformerFactory tfactory;

static {
Expand Down Expand Up @@ -157,7 +160,6 @@ public XMLDocument(final String text) {
);
}


/**
* Public ctor, from XML as a text.
*
Expand All @@ -177,7 +179,7 @@ public XMLDocument(final String text) {
* @param text XML document body
* @param factory Transformer factory
*/
public XMLDocument(final String text, TransformerFactory factory) {
public XMLDocument(final String text, final TransformerFactory factory) {
this(
new DomParser(XMLDocument.DFACTORY, text).document(),
new XPathContext(),
Expand Down Expand Up @@ -346,6 +348,14 @@ private XMLDocument(
this(node, ctx, lfe, XMLDocument.TFACTORY);
}

/**
* Private ctor.
* @param cache The source
* @param context Namespace context
* @param leaf Is it a leaf node?
* @param tfactory Transformer factory
* @checkstyle ParameterNumberCheck (5 lines)
*/
public XMLDocument(
final Node cache,
final XPathContext context,
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/jcabi/xml/XMLDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,13 @@ void comparesDocumentsWithDifferentIndentations() {
// different indentations. Don't forget to remove the @Disabled annotation from this test.
final TransformerFactory factory = TransformerFactory.newInstance(
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
this.getClass().getClassLoader()
Thread.currentThread().getContextClassLoader()
);
MatcherAssert.assertThat(
"Different indentations should be ignored",
new XMLDocument("<program>\n <indentation/>\n</program>", factory),
new XMLDocument("<program>\n <indentation/>\n</program>", factory),
Matchers.equalTo(
new XMLDocument("<program>\n <indentation/>\n</program>\n", factory)
new XMLDocument("<program>\n <indentation/>\n</program>\n", factory)
)
);
}
Expand Down
Loading