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 java.util.ArrayList;
24 import org.apache.maven.plugin.surefire.report.FileReporter;
25 import org.apache.maven.plugin.surefire.report.ReportEntryType;
26 import org.apache.maven.plugin.surefire.report.TestSetStats;
27 import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
28
29 import junit.framework.TestCase;
30
31 public class FileReporterTest
32 extends TestCase
33 {
34
35 private FileReporter reporter;
36
37 private ReportEntry reportEntry;
38
39 private static final String testName = "org.apache.maven.surefire.report.FileReporterTest";
40
41 public void testFileNameWithoutSuffix()
42 {
43 File reportDir = new File( "target" );
44 reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
45 WrappedReportEntry wrappedReportEntry =
46 new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
47 reporter = new FileReporter( reportDir, null );
48 reporter.testSetCompleted( wrappedReportEntry, createTestSetStats(), new ArrayList<String>() );
49
50 File expectedReportFile = new File( reportDir, testName + ".txt" );
51 assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
52 expectedReportFile.exists() );
53 expectedReportFile.delete();
54 }
55
56 private TestSetStats createTestSetStats()
57 {
58 return new TestSetStats( true, true );
59 }
60
61 public void testFileNameWithSuffix()
62 {
63 File reportDir = new File( "target" );
64 String suffixText = "sampleSuffixText";
65 reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
66 WrappedReportEntry wrappedReportEntry =
67 new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
68 reporter = new FileReporter( reportDir, suffixText );
69 reporter.testSetCompleted( wrappedReportEntry, createTestSetStats(), new ArrayList<String>() );
70
71 File expectedReportFile = new File( reportDir, testName + "-" + suffixText + ".txt" );
72 assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
73 expectedReportFile.exists() );
74 expectedReportFile.delete();
75 }
76
77 }