View Javadoc

1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }