1 package org.apache.maven.plugin.surefire;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }