View Javadoc
1   package org.apache.maven.plugin.surefire;
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 junit.framework.TestCase;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.surefire.api.suite.RunResult;
25  
26  import java.io.File;
27  
28  import static org.fest.assertions.Assertions.assertThat;
29  
30  /**
31   *
32   */
33  public class SurefirePluginTest extends TestCase
34  {
35      public void testDefaultIncludes()
36      {
37          assertThat( new SurefirePlugin().getDefaultIncludes() )
38                  .containsOnly( "**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java" );
39      }
40  
41      public void testReportSchemaLocation()
42      {
43          assertThat( new SurefirePlugin().getReportSchemaLocation() )
44              .isEqualTo( "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" );
45      }
46  
47      public void testFailIfNoTests() throws Exception
48      {
49          RunResult runResult = new RunResult( 0, 0, 0, 0 );
50          try
51          {
52              SurefirePlugin plugin = new SurefirePlugin();
53              plugin.setFailIfNoTests( true );
54              plugin.handleSummary( runResult, null );
55          }
56          catch ( MojoFailureException e )
57          {
58              assertThat( e.getLocalizedMessage() )
59                      .isEqualTo( "No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)" );
60              return;
61          }
62          fail( "Expected MojoFailureException with message "
63                  + "'No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)'" );
64      }
65  
66      public void testTestFailure() throws Exception
67      {
68          RunResult runResult = new RunResult( 1, 0, 1, 0 );
69          try
70          {
71              SurefirePlugin plugin = new SurefirePlugin();
72              plugin.handleSummary( runResult, null );
73          }
74          catch ( MojoFailureException e )
75          {
76              assertThat( e.getLocalizedMessage() )
77                      .isEqualTo( "There are test failures.\n\nPlease refer to null "
78                              + "for the individual test results.\nPlease refer to dump files (if any exist) "
79                              + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream." );
80              return;
81          }
82          fail( "Expected MojoFailureException with message "
83                  + "'There are test failures.\n\nPlease refer to null "
84                  + "for the individual test results.\nPlease refer to dump files (if any exist) "
85                  + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.'" );
86      }
87  
88      public void testPluginName()
89      {
90          assertThat( new SurefirePlugin().getPluginName() )
91                  .isEqualTo( "surefire" );
92      }
93  
94      public void testShouldGetNullEnv()
95      {
96          SurefirePlugin plugin = new SurefirePlugin();
97          assertThat( plugin.getExcludedEnvironmentVariables() )
98                  .hasSize( 0 );
99      }
100 
101     public void testShouldGetEnv()
102     {
103         SurefirePlugin plugin = new SurefirePlugin();
104         plugin.setExcludedEnvironmentVariables( new String[] { "ABC", "KLM" } );
105         assertThat( plugin.getExcludedEnvironmentVariables() )
106                 .hasSize( 2 )
107                 .contains( "ABC", "KLM" );
108     }
109 
110     public void testShouldGetPropertyFile()
111     {
112         SurefirePlugin plugin = new SurefirePlugin();
113         plugin.setSystemPropertiesFile( new File( "testShouldGetPropertyFile" ) );
114         assertThat( plugin.getSystemPropertiesFile() )
115                 .isEqualTo( new File( "testShouldGetPropertyFile" ) );
116     }
117 }