1 package org.apache.maven.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import org.codehaus.plexus.util.xml.Xpp3Dom;
24
25 import junit.framework.AssertionFailedError;
26 import junit.framework.TestCase;
27
28 public class XMLReporterTest
29 extends TestCase
30 {
31
32 private XMLReporter reporter;
33
34 private ReportEntry reportEntry;
35
36 private String message;
37
38 protected void setUp()
39 throws Exception
40 {
41 super.setUp();
42 reporter = new XMLReporter( true, new File( "." ));
43 message = "junit.framework.AssertionFailedError";
44 reportEntry = new SimpleReportEntry( this.getClass().getName(), "XMLReporterTest",
45 new PojoStackTraceWriter( "", "", new AssertionFailedError() ) );
46 }
47
48
49
50
51 public void testTestError()
52 {
53 reporter.testError( reportEntry, "", "" );
54 assertResult( reporter, message );
55 }
56
57
58
59
60 public void testTestFailed()
61 {
62 reporter.testError( reportEntry, "", "" );
63 assertResult( reporter, message );
64 }
65
66 private void assertResult( XMLReporter reporter, String message )
67 {
68 Xpp3Dom result = (Xpp3Dom) reporter.getResults().next();
69 Xpp3Dom child = result.getChild( "error" );
70 assertEquals( message, child.getAttribute( "type" ) );
71 }
72
73
74
75
76 public void testFileNameWithoutSuffix()
77 {
78 File reportDir = new File( "." );
79 String testName = "org.apache.maven.surefire.report.XMLReporterTest";
80 reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
81 reporter = new XMLReporter( true, reportDir, null );
82 reporter.testSetCompleted( reportEntry );
83
84 File expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
85 assertTrue("Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist", expectedReportFile.exists() );
86 expectedReportFile.delete();
87 }
88
89
90
91
92 public void testFileNameWithSuffix()
93 {
94 File reportDir = new File( "." );
95 String testName = "org.apache.maven.surefire.report.XMLReporterTest";
96 String suffixText = "sampleSuffixText";
97 reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
98 reporter = new XMLReporter( true, reportDir, suffixText );
99 reporter.testSetCompleted( reportEntry );
100
101 File expectedReportFile = new File( reportDir, "TEST-" + testName + "-" + suffixText + ".xml" );
102 assertTrue("Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist", expectedReportFile.exists() );
103 expectedReportFile.delete();
104 }
105
106 }