4141public class XmlUtilTest
4242 extends TestCase
4343{
44- private static final File basedir = new File ( new File ( "" ). getAbsolutePath () ) ;
44+ private String basedir ;
4545
46+ public final String getBasedir ()
47+ {
48+ if ( null == basedir )
49+ {
50+ basedir = System .getProperty ( "basedir" , new File ( "" ).getAbsolutePath () );
51+ }
52+ return basedir ;
53+ }
54+
4655 /** {@inheritDoc} */
4756 protected void setUp ()
4857 throws Exception
@@ -60,15 +69,15 @@ protected void tearDown()
6069 public void testPrettyFormatInputStreamOutputStream ()
6170 throws Exception
6271 {
63- File testDocument = new File ( basedir , "src/test/resources/testDocument.xhtml" );
72+ File testDocument = new File ( getBasedir () , "src/test/resources/testDocument.xhtml" );
6473 assertTrue ( testDocument .exists () );
6574
6675 InputStream is = null ;
6776 OutputStream os = null ;
6877 try
6978 {
7079 is = new FileInputStream ( testDocument );
71- os = new FileOutputStream ( new File ( basedir , "target/test/prettyFormatTestDocumentOutputStream.xml" ) );
80+ os = new FileOutputStream ( new File ( getBasedir () , "target/test/prettyFormatTestDocumentOutputStream.xml" ) );
7281
7382 assertNotNull ( is );
7483 assertNotNull ( os );
@@ -85,15 +94,15 @@ public void testPrettyFormatInputStreamOutputStream()
8594 public void testPrettyFormatReaderWriter ()
8695 throws Exception
8796 {
88- File testDocument = new File ( basedir , "src/test/resources/testDocument.xhtml" );
97+ File testDocument = new File ( getBasedir () , "src/test/resources/testDocument.xhtml" );
8998 assertTrue ( testDocument .exists () );
9099
91100 Reader reader = null ;
92101 Writer writer = null ;
93102 try
94103 {
95104 reader = ReaderFactory .newXmlReader ( testDocument );
96- writer = WriterFactory .newXmlWriter ( new File ( basedir , "target/test/prettyFormatTestDocumentWriter.xml" ) );
105+ writer = WriterFactory .newXmlWriter ( new File ( getBasedir () , "target/test/prettyFormatTestDocumentWriter.xml" ) );
97106
98107 assertNotNull ( reader );
99108 assertNotNull ( writer );
@@ -110,7 +119,7 @@ public void testPrettyFormatReaderWriter()
110119 public void testPrettyFormatString ()
111120 throws Exception
112121 {
113- File testDocument = new File ( basedir , "src/test/resources/testDocument.xhtml" );
122+ File testDocument = new File ( getBasedir () , "src/test/resources/testDocument.xhtml" );
114123 assertTrue ( testDocument .exists () );
115124
116125 Reader reader = null ;
@@ -140,15 +149,15 @@ public void testPrettyFormatString()
140149 public void testPrettyFormatReaderWriter2 ()
141150 throws Exception
142151 {
143- File testDocument = new File ( basedir , "src/test/resources/test.xdoc.xhtml" );
152+ File testDocument = new File ( getBasedir () , "src/test/resources/test.xdoc.xhtml" );
144153 assertTrue ( testDocument .exists () );
145154
146155 Reader reader = null ;
147156 Writer writer = null ;
148157 try
149158 {
150159 reader = ReaderFactory .newXmlReader ( testDocument );
151- writer = WriterFactory .newXmlWriter ( new File ( basedir , "target/test/prettyFormatTestXdocWriter.xml" ) );
160+ writer = WriterFactory .newXmlWriter ( new File ( getBasedir () , "target/test/prettyFormatTestXdocWriter.xml" ) );
152161
153162 assertNotNull ( reader );
154163 assertNotNull ( writer );
@@ -160,5 +169,5 @@ public void testPrettyFormatReaderWriter2()
160169 IOUtil .close ( reader );
161170 IOUtil .close ( writer );
162171 }
163- }
172+ }
164173}
0 commit comments