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