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