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 org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
23  import org.apache.maven.surefire.suite.RunResult;
24  
25  import junit.framework.TestCase;
26  
27  public class SummaryTest
28      extends TestCase
29  {
30      Summary summary = new Summary();
31  
32      public void testEmptySummaryShouldBeErrorFree()
33      {
34          assertTrue( summary.isErrorFree() );
35      }
36  
37      public void testSummaryShouldBeErrorFreeAfterAddingAnException()
38      {
39          summary.registerException( new RuntimeException() );
40          assertFalse( summary.isErrorFree() );
41      }
42  
43      public void testEmptySummaryShouldHaveNoFailureOrTimeOut()
44      {
45          assertFalse( summary.isFailureOrTimeout() );
46      }
47  
48      public void testSummaryReturnsFailureOrTimeOutStateOfLastRun()
49      {
50          RunResult resultWithoutFailure = new RunResult( 0, 0, 0, 0, false, false );
51          RunResult resultWithFailure = new RunResult( 0, 0, 0, 0, true, true );
52          summary.registerRunResult( resultWithoutFailure );
53          summary.registerRunResult( resultWithFailure );
54          assertTrue( summary.isFailureOrTimeout() );
55      }
56  
57      public void testEmptySummaryHasNoFirstException()
58      {
59          assertNull( summary.getFirstException() );
60      }
61  
62      public void testSummaryReturnsTheFirstOfTwoExceptions()
63      {
64          Exception exceptionOne = new RuntimeException();
65          Exception exceptionTwo = new RuntimeException();
66          summary.registerException( exceptionOne );
67          summary.registerException( exceptionTwo );
68          assertEquals( "Wrong exception.", exceptionOne, summary.getFirstException() );
69      }
70  
71      public void testEmptySummaryHasNoResultOfLastSuccessfulRun()
72      {
73          assertNull( summary.getResultOfLastSuccessfulRun() );
74      }
75  
76      public void testSummaryReturnsTheSecondOfTwoResult()
77      {
78          RunResult resultOne = new RunResult( 0, 0, 0, 0 );
79          RunResult resultTwo = new RunResult( 0, 0, 0, 0 );
80          summary.registerRunResult( resultOne );
81          summary.registerRunResult( resultTwo );
82          assertEquals( "Wrong exception.", resultTwo, summary.getResultOfLastSuccessfulRun() );
83      }
84  
85      public void testEmptySummaryIsNotForking()
86      {
87          assertFalse( summary.isForking() );
88      }
89  
90      public void testSummaryIsForkingIfTheLastConfigurationIsForking()
91      {
92          summary.reportForkConfiguration( createNonForkingConfiguration() );
93          summary.reportForkConfiguration( createForkingConfiguration() );
94          assertTrue( summary.isForking() );
95      }
96  
97      public void testSummaryIsNotForkingIfTheLastConfigurationIsNotForking()
98      {
99          summary.reportForkConfiguration( createForkingConfiguration() );
100         summary.reportForkConfiguration( createNonForkingConfiguration() );
101         assertFalse( summary.isForking() );
102     }
103 
104     private ForkConfiguration createForkingConfiguration()
105     {
106         return new ForkConfiguration( null, ForkConfiguration.FORK_ALWAYS, null );
107     }
108 
109     private ForkConfiguration createNonForkingConfiguration()
110     {
111         return new ForkConfiguration( null, ForkConfiguration.FORK_NEVER, null );
112     }
113 }