~ubuntu-branches/ubuntu/precise/surefire/precise

« back to all changes in this revision

Viewing changes to surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2011-10-10 20:42:16 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20111010204216-cemva69wkagf4fay
Tags: 2.10-1
* Team upload.
* New upstream release.
* Refresh and remove unneccesary patches.
* Add Build-Depends on libsurefire-java and
  libmaven-common-artifact-filters-java.
* Drop outdated Maven artifact surefire-junit.
* Provide new Maven artifacts: surefire-junit3, maven-surefire-common,
  common-junit3, common-junit4, surefire-junit47 and surefire-testng-utils.
* Fix clean target to allow "two in a row" builds.
* Update Vcs-Browser field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.apache.maven.surefire.report;
 
2
 
 
3
import java.util.Collection;
 
4
import junit.framework.TestCase;
 
5
 
 
6
/*
 
7
 * Copyright 2002-2009 the original author or authors.
 
8
 *
 
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
 
12
 *
 
13
 *      http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
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.
 
20
 *
 
21
 */
 
22
 
 
23
public class RunStatisticsTest
 
24
    extends TestCase
 
25
{
 
26
    private static final String DUMMY_ERROR_SOURCE = "dummy error source";
 
27
 
 
28
    private static final String DUMMY_FAILURE_SOURCE = "dummy failure source";
 
29
 
 
30
    private static final String DUMMY_MESSAGE = "dummy message";
 
31
 
 
32
    public void testAddErrorSourceWithThrowableMessage()
 
33
    {
 
34
        RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
 
35
        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable );
 
36
        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE + ": " + DUMMY_MESSAGE );
 
37
    }
 
38
 
 
39
    public void testAddErrorSourceWithoutStackTraceWriter()
 
40
    {
 
41
        RunStatistics statistics = new RunStatistics();
 
42
        statistics.addErrorSource( DUMMY_ERROR_SOURCE, null );
 
43
        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
 
44
    }
 
45
 
 
46
    public void testAddErrorSourceWithoutThrowable()
 
47
    {
 
48
        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( null );
 
49
        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
 
50
    }
 
51
 
 
52
    public void testAddErrorSourceWithThrowableWithoutMessage()
 
53
    {
 
54
        RuntimeException throwable = new RuntimeException();
 
55
        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable );
 
56
        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
 
57
    }
 
58
 
 
59
    public void testAddFailureSourceWithThrowableMessage()
 
60
    {
 
61
        RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
 
62
        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable );
 
63
        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE + ": " + DUMMY_MESSAGE );
 
64
    }
 
65
 
 
66
    public void testAddFailureSourceWithoutStackTraceWriter()
 
67
    {
 
68
        RunStatistics statistics = new RunStatistics();
 
69
        statistics.addFailureSource( DUMMY_FAILURE_SOURCE, null );
 
70
        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
 
71
    }
 
72
 
 
73
    public void testAddFailureSourceWithoutThrowable()
 
74
    {
 
75
        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( null );
 
76
        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
 
77
    }
 
78
 
 
79
    public void testAddFailureSourceWithThrowableWithoutMessage()
 
80
    {
 
81
        RuntimeException throwable = new RuntimeException();
 
82
        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable );
 
83
        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
 
84
    }
 
85
 
 
86
    private RunStatistics createRunStatisticsAndAddErrorSourceWithThrowable( Throwable throwable )
 
87
    {
 
88
        StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable );
 
89
        RunStatistics statistics = new RunStatistics();
 
90
        statistics.addErrorSource( DUMMY_ERROR_SOURCE, stackTraceWriter );
 
91
 
 
92
        return statistics;
 
93
    }
 
94
 
 
95
    private RunStatistics createRunStatisticsAndAddFailureSourceWithThrowable( Throwable throwable )
 
96
    {
 
97
        StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable );
 
98
        RunStatistics statistics = new RunStatistics();
 
99
        statistics.addFailureSource( DUMMY_FAILURE_SOURCE, stackTraceWriter );
 
100
 
 
101
        return statistics;
 
102
    }
 
103
 
 
104
    private void assertRunStatisticsHasErrorSource( RunStatistics statistics, String expectedErrorSource )
 
105
    {
 
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() );
 
110
    }
 
111
 
 
112
    private void assertRunStatisticsHasFailureSource( RunStatistics statistics, String expectedFailureSource )
 
113
    {
 
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() );
 
118
    }
 
119
}