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