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 org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
24  
25  import junit.framework.TestCase;
26  
27  public class ConsoleOutputFileReporterTest
28      extends TestCase
29  {
30  
31      private ConsoleOutputFileReporter reporter;
32  
33      private ReportEntry reportEntry;
34  
35      private static final String testName = "org.apache.maven.surefire.report.ConsoleOutputFileReporterTest";
36  
37      /*
38       * Test method for 'org.codehaus.surefire.report.ConsoleOutputFileReporter.testSetCompleted(ReportEntry report)'
39       */
40      public void testFileNameWithoutSuffix()
41      {
42          File reportDir = new File( System.getProperty( "java.io.tmpdir" ) );
43          reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
44          reporter = new ConsoleOutputFileReporter( reportDir, null );
45          reporter.testSetStarting( reportEntry );
46          reporter.writeTestOutput( "some text".getBytes(), 0, 5, true );
47          reporter.testSetCompleted( reportEntry );
48  
49          File expectedReportFile = new File( reportDir, testName + "-output.txt" );
50          assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
51                      expectedReportFile.exists() );
52          expectedReportFile.delete();
53      }
54  
55      /*
56       * Test method for 'org.codehaus.surefire.report.ConsoleOutputFileReporter.testSetCompleted(ReportEntry report)'
57       */
58      public void testFileNameWithSuffix()
59      {
60          File reportDir = new File( System.getProperty( "java.io.tmpdir" ) );
61          String suffixText = "sampleSuffixText";
62          reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
63          reporter = new ConsoleOutputFileReporter( reportDir, suffixText );
64          reporter.testSetStarting( reportEntry );
65          reporter.writeTestOutput( "some text".getBytes(), 0, 5, true );
66          reporter.testSetCompleted( reportEntry );
67  
68          File expectedReportFile = new File( reportDir, testName + "-" + suffixText + "-output.txt" );
69          assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
70                      expectedReportFile.exists() );
71          expectedReportFile.delete();
72      }
73  
74  }