View Javadoc
1   package org.apache.maven.surefire.its;
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 org.apache.commons.lang3.StringUtils;
23  import org.apache.maven.surefire.its.fixture.OutputValidator;
24  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
26  import org.junit.Test;
27  
28  import java.io.IOException;
29  
30  import static org.junit.Assert.assertFalse;
31  import static org.junit.Assert.assertNotNull;
32  
33  public class JUnit47RedirectOutputIT
34      extends SurefireJUnit4IntegrationTestCase
35  {
36      @Test
37      public void testPrintSummaryTrueWithRedirect()
38          throws Exception
39      {
40          final OutputValidator clean = unpack().redirectToFile( true ).addGoal( "clean" ).executeTest();
41          checkReports( clean );
42      }
43  
44      @Test
45      public void testClassesParallel()
46          throws Exception
47      {
48          final OutputValidator clean =
49              unpack().redirectToFile( true ).parallelClasses().addGoal( "clean" ).executeTest();
50          checkReports( clean );
51      }
52  
53      private void checkReports( OutputValidator validator )
54          throws IOException
55      {
56          String report = StringUtils.trimToNull(
57              validator.getSurefireReportsFile( "junit47ConsoleOutput.Test1-output.txt" ).readFileToString() );
58          assertNotNull( report );
59          String report2 = StringUtils.trimToNull(
60              validator.getSurefireReportsFile( "junit47ConsoleOutput.Test2-output.txt" ).readFileToString() );
61          assertNotNull( report2 );
62          assertFalse( validator.getSurefireReportsFile( "junit47ConsoleOutput.Test3-output.txt" ).exists() );
63      }
64  
65  
66      private SurefireLauncher unpack()
67      {
68          return unpack( "/junit47-redirect-output" );
69      }
70  
71  }