1
package org.apache.maven.surefire.report;
3
import java.util.Collection;
4
import junit.framework.TestCase;
7
* Copyright 2002-2009 the original author or authors.
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
23
public class RunStatisticsTest
26
private static final String DUMMY_ERROR_SOURCE = "dummy error source";
28
private static final String DUMMY_FAILURE_SOURCE = "dummy failure source";
30
private static final String DUMMY_MESSAGE = "dummy message";
32
public void testAddErrorSourceWithThrowableMessage()
34
RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
35
RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable );
36
assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE + ": " + DUMMY_MESSAGE );
39
public void testAddErrorSourceWithoutStackTraceWriter()
41
RunStatistics statistics = new RunStatistics();
42
statistics.addErrorSource( DUMMY_ERROR_SOURCE, null );
43
assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
46
public void testAddErrorSourceWithoutThrowable()
48
RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( null );
49
assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
52
public void testAddErrorSourceWithThrowableWithoutMessage()
54
RuntimeException throwable = new RuntimeException();
55
RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable );
56
assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
59
public void testAddFailureSourceWithThrowableMessage()
61
RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
62
RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable );
63
assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE + ": " + DUMMY_MESSAGE );
66
public void testAddFailureSourceWithoutStackTraceWriter()
68
RunStatistics statistics = new RunStatistics();
69
statistics.addFailureSource( DUMMY_FAILURE_SOURCE, null );
70
assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
73
public void testAddFailureSourceWithoutThrowable()
75
RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( null );
76
assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
79
public void testAddFailureSourceWithThrowableWithoutMessage()
81
RuntimeException throwable = new RuntimeException();
82
RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable );
83
assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
86
private RunStatistics createRunStatisticsAndAddErrorSourceWithThrowable( Throwable throwable )
88
StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable );
89
RunStatistics statistics = new RunStatistics();
90
statistics.addErrorSource( DUMMY_ERROR_SOURCE, stackTraceWriter );
95
private RunStatistics createRunStatisticsAndAddFailureSourceWithThrowable( Throwable throwable )
97
StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable );
98
RunStatistics statistics = new RunStatistics();
99
statistics.addFailureSource( DUMMY_FAILURE_SOURCE, stackTraceWriter );
104
private void assertRunStatisticsHasErrorSource( RunStatistics statistics, String expectedErrorSource )
106
Collection errorSources = statistics.getErrorSources();
107
assertNotNull( "No error sources.", errorSources );
108
assertEquals( "Wrong number of error sources.", 1, errorSources.size() );
109
assertEquals( "Wrong error sources.", expectedErrorSource, errorSources.iterator().next() );
112
private void assertRunStatisticsHasFailureSource( RunStatistics statistics, String expectedFailureSource )
114
Collection failureSources = statistics.getFailureSources();
115
assertNotNull( "No failure sources.", failureSources );
116
assertEquals( "Wrong number of failure sources.", 1, failureSources.size() );
117
assertEquals( "Wrong failure sources.", expectedFailureSource, failureSources.iterator().next() );