KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > RootNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output;
21
22 import java.awt.EventQueue JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.Children;
27 import org.openide.util.NbBundle;
28
29 /**
30  *
31  * @author Marian Petras
32  */

33 final class RootNode extends AbstractNode {
34
35     /** */
36     static final String JavaDoc name = "JUnit results root node"; //NOI18N
37

38     /** constant meaning "information about passed tests not displayed" */
39     static final int ALL_PASSED_ABSENT = 0;
40     /** constant meaning "information about some passed tests not displayed" */
41     static final int SOME_PASSED_ABSENT = 1;
42     /** constant meaning "information about all passed tests displayed */
43     static final int ALL_PASSED_DISPLAYED = 2;
44
45     /**
46      */

47     private final RootNodeChildren children;
48     
49     /**
50      */

51     private volatile boolean filtered;
52     /** */
53     private volatile String JavaDoc message;
54     
55     private volatile int totalTests = 0;
56     private volatile int failures = 0;
57     private volatile int errors = 0;
58     private volatile int elapsedTimeMillis = 0;
59     private volatile int detectedPassedTests = 0;
60     
61     
62     /**
63      * Creates a new instance of RootNode
64      */

65     public RootNode(final boolean filtered) {
66         super(new RootNodeChildren(filtered));
67         this.filtered = filtered;
68         children = (RootNodeChildren) getChildren();
69         setName(name); //used by tree cell renderer to recognize the root node
70
setIconBaseWithExtension(
71                 "org/netbeans/modules/junit/output/res/empty.gif"); //NOI18N
72
}
73     
74     /**
75      */

76     void displayMessage(final String JavaDoc msg) {
77         assert EventQueue.isDispatchThread();
78         
79         /* Called from the EventDispatch thread */
80         
81         this.message = msg;
82         updateDisplayName();
83     }
84     
85     /**
86      * Displays a message that a given test suite is running.
87      *
88      * @param suiteName name of the running test suite,
89      * or {@code ANONYMOUS_SUITE} for anonymous suites
90      *
91      * @see ResultDisplayHandler#ANONYMOUS_SUITE
92      */

93     void displaySuiteRunning(final String JavaDoc suiteName) {
94         assert EventQueue.isDispatchThread();
95         
96         /* Called from the EventDispatch thread */
97         
98         children.displaySuiteRunning(suiteName);
99     }
100     
101     /**
102      */

103     TestsuiteNode displayReport(final Report report) {
104         assert EventQueue.isDispatchThread();
105         
106         /* Called from the EventDispatch thread */
107         
108         updateStatistics(report);
109         updateDisplayName();
110         return children.displayReport(report);
111     }
112     
113     /**
114      */

115     void displayReports(final Collection JavaDoc<Report> reports) {
116         assert EventQueue.isDispatchThread();
117         
118         /* Called from the EventDispatch thread */
119         
120         for (Report report : reports) {
121             updateStatistics(report);
122         }
123         updateDisplayName();
124         children.displayReports(reports);
125     }
126     
127     /**
128      */

129     private void updateStatistics(final Report report) {
130         totalTests += report.totalTests;
131         failures += report.failures;
132         errors += report.errors;
133         detectedPassedTests += report.detectedPassedTests;
134         elapsedTimeMillis += report.elapsedTimeMillis;
135     }
136     
137     /**
138      */

139     void setFiltered(final boolean filtered) {
140         assert EventQueue.isDispatchThread();
141         
142         if (filtered == this.filtered) {
143             return;
144         }
145         this.filtered = filtered;
146         
147         Children children = getChildren();
148         if (children != Children.LEAF) {
149             ((RootNodeChildren) children).setFiltered(filtered);
150         }
151     }
152     
153     /**
154      */

155     private void updateDisplayName() {
156         assert EventQueue.isDispatchThread();
157         
158         /* Called from the EventDispatch thread */
159         
160         final Class JavaDoc bundleRefClass = getClass();
161         String JavaDoc msg;
162
163         if (totalTests == 0) {
164             msg = null;
165         } else if ((failures == 0) && (errors == 0)) {
166             msg = NbBundle.getMessage(bundleRefClass,
167                                       "MSG_TestsInfoAllOK", //NOI18N
168
new Integer JavaDoc(totalTests));
169         } else {
170             String JavaDoc passedTestsInfo = NbBundle.getMessage(
171                     bundleRefClass,
172                     "MSG_PassedTestsInfo", //NOI18N
173
new Integer JavaDoc(totalTests - failures - errors));
174             String JavaDoc failedTestsInfo = (failures == 0)
175                                      ? null
176                                      : NbBundle.getMessage(
177                                             bundleRefClass,
178                                             "MSG_FailedTestsInfo", //NOI18N
179
new Integer JavaDoc(failures));
180             String JavaDoc errorTestsInfo = (errors == 0)
181                                     ? null
182                                     : NbBundle.getMessage(
183                                             bundleRefClass,
184                                             "MSG_ErrorTestsInfo", //NOI18N
185
new Integer JavaDoc(errors));
186             if ((failedTestsInfo == null) || (errorTestsInfo == null)) {
187                 msg = NbBundle.getMessage(bundleRefClass,
188                                           "MSG_TestsOneIssueType", //NOI18N
189
passedTestsInfo,
190                                           failedTestsInfo != null
191                                                 ? failedTestsInfo
192                                                 : errorTestsInfo);
193             } else {
194                 msg = NbBundle.getMessage(bundleRefClass,
195                                           "MSG_TestsFailErrIssues", //NOI18N
196
passedTestsInfo,
197                                           failedTestsInfo,
198                                           errorTestsInfo);
199             }
200         }
201
202         if (totalTests != 0) {
203             assert msg != null;
204             final int successDisplayedLevel = getSuccessDisplayedLevel();
205             switch (successDisplayedLevel) {
206                 case SOME_PASSED_ABSENT:
207                     msg += ' ';
208                     msg += NbBundle.getMessage(
209                                         bundleRefClass,
210                                         "MSG_SomePassedNotDisplayed"); //NOI18N
211
break;
212                 case ALL_PASSED_ABSENT:
213                     msg += ' ';
214                     msg += NbBundle.getMessage(
215                                         bundleRefClass,
216                                         "MSG_PassedNotDisplayed"); //NOI18N
217
break;
218                 case ALL_PASSED_DISPLAYED:
219                     break;
220                 default:
221                     assert false;
222                     break;
223             }
224         }
225         
226         if (this.message != null) {
227             if (msg == null) {
228                 msg = this.message;
229             } else {
230                 msg = msg + ' ' + message;
231             }
232         }
233
234         setDisplayName(msg);
235     }
236     
237     /**
238      * Returns information whether information about passed tests is displayed.
239      *
240      * @return one of constants <code>ALL_PASSED_DISPLAYED</code>,
241      * <code>SOME_PASSED_ABSENT</code>,
242      * <code>ALL_PASSED_ABSENT</code>
243      */

244     int getSuccessDisplayedLevel() {
245         int reportedPassedTestsCount = totalTests - failures - errors;
246         if (detectedPassedTests >= reportedPassedTestsCount) {
247             return ALL_PASSED_DISPLAYED;
248         } else if (detectedPassedTests == 0) {
249             return ALL_PASSED_ABSENT;
250         } else {
251             return SOME_PASSED_ABSENT;
252         }
253     }
254     
255 }
256
Popular Tags