View Javadoc
1   package org.apache.maven.surefire.its.jiras;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.maven.surefire.its.fixture.OutputValidator;
22  import org.apache.maven.surefire.its.fixture.SurefireVerifierException;
23  import org.junit.Test;
24  import org.junit.runner.RunWith;
25  import org.junit.runners.Parameterized;
26  
27  import java.util.ArrayList;
28  
29  import static org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase.unpack;
30  import static org.junit.runners.Parameterized.*;
31  import static org.junit.Assert.*;
32  
33  /**
34   *
35   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
36   * @see <a href="https://issues.apache.org/jira/browse/SUREFIRE-1158">SUREFIRE-1158</a>
37   * @since 2.19
38   */
39  @RunWith( Parameterized.class )
40  public class Surefire1158RemoveInfoLinesIT
41  {
42  
43      @Parameters(name = "{0}")
44      public static Iterable<Object[]> data()
45      {
46          ArrayList<Object[]> args = new ArrayList<Object[]>();
47          args.add( new Object[] { "junit-option-ff", "JUnitTest", "-ff", "surefire-junit47", false, true } );
48          args.add( new Object[] { "testng-option-ff", "TestNGSuiteTest", "-ff", "surefire-testng", false, false } );
49          args.add( new Object[] { "junit-option-X", "JUnitTest", "-X", "surefire-junit47", true, true } );
50          args.add( new Object[] { "testng-option-X", "TestNGSuiteTest", "-X", "surefire-testng", true, false } );
51          args.add( new Object[] { "junit-option-e", "JUnitTest", "-e", "surefire-junit47", true, true } );
52          args.add( new Object[] { "testng-option-e", "TestNGSuiteTest", "-e", "surefire-testng", true, false } );
53          return args;
54      }
55  
56      @Parameter(0)
57      public String description;
58  
59      @Parameter(1)
60      public String testToRun;
61  
62      @Parameter(2)
63      public String cliOption;
64  
65      @Parameter(3)
66      public String provider;
67  
68      @Parameter(4)
69      public boolean printsInfoLines;
70  
71      @Parameter(5)
72      public boolean isJUnit;
73  
74      @Test
75      public void shouldRunWithCliOption()
76          throws Exception
77      {
78          OutputValidator validator = assertTest();
79          if ( isJUnit )
80          {
81              assertJUnitTestLogs( validator );
82          }
83          else
84          {
85              assertTestNGTestLogs( validator );
86          }
87      }
88  
89      private OutputValidator assertTest()
90          throws Exception
91      {
92          final String[] cli = {"--batch-mode"};
93          return unpack( getClass(), "/surefire-1158-remove-info-lines", "_" + description, cli )
94              .sysProp( "provider", provider ).addGoal( cliOption ).setTestToRun( testToRun )
95              .executeTest()
96              .verifyErrorFreeLog().assertTestSuiteResults( 1, 0, 0, 0 );
97      }
98  
99      private void assertJUnitTestLogs( OutputValidator validator )
100     {
101         try
102         {
103             validator.verifyTextInLog( "Surefire report directory:" );
104             validator.verifyTextInLog( "Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider" );
105             validator.verifyTextInLog( "parallel='none', perCoreThreadCount=true, threadCount=0, "
106                                            + "useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, "
107                                            + "threadCountMethods=0, parallelOptimized=true" );
108             if ( !printsInfoLines )
109             {
110                 fail();
111             }
112         }
113         catch ( SurefireVerifierException e )
114         {
115             if ( printsInfoLines )
116             {
117                 fail();
118             }
119         }
120     }
121 
122     private void assertTestNGTestLogs( OutputValidator validator )
123     {
124         try
125         {
126             validator.verifyTextInLog( "Surefire report directory:" );
127             validator.verifyTextInLog( "Using configured provider org.apache.maven.surefire.testng.TestNGProvider" );
128             validator.verifyTextInLog( "Configuring TestNG with: TestNGMapConfigurator" );
129             if ( !printsInfoLines )
130             {
131                 fail();
132             }
133         }
134         catch ( SurefireVerifierException e )
135         {
136             if ( printsInfoLines )
137             {
138                 fail();
139             }
140         }
141     }
142 }