Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 57b636d

Browse files
committed
changed XmlUtilTest to create test output directory
the test was sensitive to overall test execution order and was failing if it happended to run before other tests that created target/test directory. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
1 parent 33091f9 commit 57b636d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.io.FileInputStream;
2121
import java.io.FileOutputStream;
22+
import java.io.IOException;
2223
import java.io.InputStream;
2324
import java.io.OutputStream;
2425
import java.io.Reader;
@@ -51,7 +52,19 @@ public final String getBasedir()
5152
}
5253
return basedir;
5354
}
54-
55+
56+
private File getTestOutputFile( String relPath )
57+
throws IOException
58+
{
59+
final File file = new File( getBasedir(), relPath );
60+
final File parentFile = file.getParentFile();
61+
if ( !parentFile.isDirectory() && !parentFile.mkdirs() )
62+
{
63+
throw new IOException( "Could not create test directory " + parentFile );
64+
}
65+
return file;
66+
}
67+
5568
/** {@inheritDoc} */
5669
protected void setUp()
5770
throws Exception
@@ -77,7 +90,7 @@ public void testPrettyFormatInputStreamOutputStream()
7790
try
7891
{
7992
is = new FileInputStream( testDocument );
80-
os = new FileOutputStream( new File( getBasedir(), "target/test/prettyFormatTestDocumentOutputStream.xml" ) );
93+
os = new FileOutputStream( getTestOutputFile( "target/test/prettyFormatTestDocumentOutputStream.xml" ) );
8194

8295
assertNotNull( is );
8396
assertNotNull( os );
@@ -102,7 +115,7 @@ public void testPrettyFormatReaderWriter()
102115
try
103116
{
104117
reader = ReaderFactory.newXmlReader( testDocument );
105-
writer = WriterFactory.newXmlWriter( new File( getBasedir(), "target/test/prettyFormatTestDocumentWriter.xml" ) );
118+
writer = WriterFactory.newXmlWriter( getTestOutputFile( "target/test/prettyFormatTestDocumentWriter.xml" ) );
106119

107120
assertNotNull( reader );
108121
assertNotNull( writer );
@@ -157,7 +170,7 @@ public void testPrettyFormatReaderWriter2()
157170
try
158171
{
159172
reader = ReaderFactory.newXmlReader( testDocument );
160-
writer = WriterFactory.newXmlWriter( new File( getBasedir(), "target/test/prettyFormatTestXdocWriter.xml" ) );
173+
writer = WriterFactory.newXmlWriter( getTestOutputFile( "target/test/prettyFormatTestXdocWriter.xml" ) );
161174

162175
assertNotNull( reader );
163176
assertNotNull( writer );

0 commit comments

Comments
 (0)