package org.apache.maven.javadoc; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; /** * * @author Steven Caswell * @version $Id$ */ public class JavadocWarningsTextToXmlTest extends TestCase { private static final String INPUT_FILE_NAME_EXCEPTION = "Input file name must be specified"; private static final String OUTPUT_FILE_NAME_EXCEPTION = "Output file name must be specified"; public static void main(final String[] main) { TestRunner.run(suite()); } public static Test suite() { return new TestSuite(JavadocWarningsTextToXmlTest.class); } public JavadocWarningsTextToXmlTest(final String name) { super(name); } public void testInputFile() throws Exception { JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml(); bean.setOutputFileName("test.xml"); bean.setOutputEncoding("ISO-8859-1]"); try { bean.build(); } catch(NullPointerException e) { assertEquals("exception message", INPUT_FILE_NAME_EXCEPTION, e.getMessage()); } } public void testOutputFile() throws Exception { JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml(); bean.setInputFileName("report.txt"); bean.setOutputEncoding("ISO-8859-1]"); try { bean.build(); fail("Expected null pointer exception for input file name"); } catch(NullPointerException e) { assertEquals("exception message", OUTPUT_FILE_NAME_EXCEPTION, e.getMessage()); } } public void testInputFileNotFound() throws Exception { JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml(); bean.setInputFileName("junk.dat"); bean.setOutputFileName("test.xml"); bean.setOutputEncoding("ISO-8859-1]"); try { bean.build(); fail("Expected null pointer exception for input file name"); } catch(FileNotFoundException e) { ; // expected file not found } } public void testBuild() throws Exception { JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml(); bean.setInputFileName("report.txt"); bean.setOutputFileName("test.xml"); bean.setOutputEncoding("ISO-8859-1"); bean.build(); // Read and test the output file contents BufferedReader reader = new BufferedReader(new FileReader("test.xml")); String line = reader.readLine(); assertTrue("line 1 start", line.startsWith("")); line = reader.readLine(); assertEquals("line 2", "", line); line = reader.readLine(); assertTrue("line 3 start", line.startsWith("")); line = reader.readLine(); assertEquals("line 4", "", line); line = reader.readLine(); assertEquals("line 5", "", line); line = reader.readLine(); assertTrue("line 6 start", line.startsWith("")); line = reader.readLine(); assertEquals("line 7", "", line); line = reader.readLine(); assertEquals("line 8", "", line); line = reader.readLine(); assertEquals("line 9", "", line); line = reader.readLine(); assertEquals("line 10", "", line); reader.close(); // Get rid of the xml file File file = new File("test.xml"); file.delete(); } }