1   package org.apache.maven.surefire.its;
2   
3   
4   import junit.framework.TestCase;
5   import org.apache.maven.it.VerificationException;
6   import org.apache.maven.it.Verifier;
7   import org.apache.maven.it.util.ResourceExtractor;
8   import org.apache.maven.reporting.MavenReportException;
9   
10  import java.io.File;
11  import java.io.IOException;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Test failIfNoTests with various forkModes.
17   * 
18   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
19   * 
20   */
21  public class TestFailIfNoTestsForkMode
22      extends TestCase
23  {
24      public void testFailIfNoTestsForkModeAlways () throws Exception
25      {
26          doTest("always", true);
27      }
28      
29      public void testFailIfNoTestsForkModeNever() throws Exception 
30      {
31          doTest( "never", true );
32      }
33      
34      public void testFailIfNoTestsForkModeOnce() throws Exception 
35      {
36          doTest( "once", true );
37      }
38      
39      public void testDontFailIfNoTestsForkModeAlways () throws Exception
40      {
41          doTest("always", false);
42      }
43      
44      public void testDontFailIfNoTestsForkModeNever() throws Exception 
45      {
46          doTest( "never", false );
47      }
48      
49      public void testDontFailIfNoTestsForkModeOnce() throws Exception 
50      {
51          doTest( "once", false );
52      }
53      
54      private void doTest(String forkMode, boolean failIfNoTests)
55          throws IOException, VerificationException, MavenReportException
56      {
57          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-classWithNoTests" );
58  
59          Verifier verifier = new Verifier( testDir.getAbsolutePath() );
60          List goals = new ArrayList();
61          goals.add( "test" );
62          goals.add( "-DforkMode=" + forkMode );
63          goals.add( "-DfailIfNoTests=" + failIfNoTests );
64          if (failIfNoTests)
65          {
66              try 
67              {
68                  verifier.executeGoals( goals );
69                  verifier.resetStreams();
70                  verifier.verifyErrorFreeLog();
71                  fail( "Build did not fail, but it should have" );
72              } catch (VerificationException e )
73              {
74                  // this is what we expected
75              }
76          }
77          else
78          {
79              verifier.executeGoals( goals );
80              verifier.resetStreams();
81              verifier.verifyErrorFreeLog();
82              HelperAssertions.assertTestSuiteResults( 0, 0, 0, 0, testDir );
83          }
84      }
85  }