View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.its;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.apache.maven.surefire.its.fixture.OutputValidator;
23  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertFalse;
28  import static org.junit.Assert.assertNotNull;
29  
30  /**
31   *
32   */
33  public class JUnit47RedirectOutputIT extends SurefireJUnit4IntegrationTestCase {
34      @Test
35      public void testPrintSummaryTrueWithRedirect() {
36          final OutputValidator clean =
37                  unpack().redirectToFile(true).addGoal("clean").executeTest();
38          checkReports(clean);
39      }
40  
41      @Test
42      public void testClassesParallel() {
43          final OutputValidator clean =
44                  unpack().redirectToFile(true).parallelClasses().addGoal("clean").executeTest();
45          checkReports(clean);
46      }
47  
48      private void checkReports(OutputValidator validator) {
49          String report = StringUtils.trimToNull(validator
50                  .getSurefireReportsFile("junit47ConsoleOutput.Test1-output.txt")
51                  .readFileToString());
52          assertNotNull(report);
53          String report2 = StringUtils.trimToNull(validator
54                  .getSurefireReportsFile("junit47ConsoleOutput.Test2-output.txt")
55                  .readFileToString());
56          assertNotNull(report2);
57          assertFalse(validator
58                  .getSurefireReportsFile("junit47ConsoleOutput.Test3-output.txt")
59                  .exists());
60      }
61  
62      private SurefireLauncher unpack() {
63          return unpack("/junit47-redirect-output");
64      }
65  }