Skip to content

Commit

Permalink
HBX-2916: Move XMLPrettyPrinter to the API and offer the ability to s…
Browse files Browse the repository at this point in the history
…pecify the XMLPrettyPrinterStrategy

  - Move class 'org.hibernate.tool.internal.xml.XMLPrettyPrinter' to 'org.hibernate.tool.api.xml.XMLPrettyPrinter'
  - Add a new test class 'org.hibernate.tool.api.xml.XMLPrettyPrinterTest'

Signed-off-by: Koen Aers <[email protected]>
  • Loading branch information
koentsje committed Sep 2, 2024
1 parent f2c8234 commit 002503d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created on 17-Dec-2004
*
*/
package org.hibernate.tool.internal.xml;
package org.hibernate.tool.api.xml;

import java.io.File;
import java.io.IOException;
Expand All @@ -11,6 +11,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import org.hibernate.tool.internal.xml.XMLPrettyPrinterStrategyFactory;

/**
* @author max
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Set;

import org.hibernate.tool.api.export.ArtifactCollector;
import org.hibernate.tool.internal.xml.XMLPrettyPrinter;
import org.hibernate.tool.api.xml.XMLPrettyPrinter;

/**
* Callback class that all exporters are given to allow better feedback and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private static XMLPrettyPrinterStrategy loadFromSystemProperty() {
throw new RuntimeException(e);
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.hibernate.tool.api.xml;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.PrintWriter;
import java.nio.file.Files;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class XMLPrettyPrinterTest {

private static final String XML_BEFORE = "<foo><bar>foobar</bar></foo>";

private static final String XML_AFTER =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
"<foo>\n" +
" <bar>foobar</bar>\n" +
"</foo>\n";

private static final String fileName = "foobarfile.xml";

@TempDir
private File tempDir;

private File xmlFile = null;

@BeforeEach
public void beforeEach() throws Exception {
xmlFile = new File(tempDir, fileName);
PrintWriter writer = new PrintWriter(xmlFile);
writer.print(XML_BEFORE);
writer.flush();
writer.close();
}

@Test
public void testXmlPrettyPrintDefault() throws Exception {
XMLPrettyPrinter.prettyPrintFile(xmlFile);
String result = Files.readString(xmlFile.toPath());
assertEquals(XML_AFTER, result);
}

}

0 comments on commit 002503d

Please sign in to comment.