KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.Action JavaDoc;
23 import org.openide.nodes.AbstractNode;
24 import org.openide.nodes.Children;
25 import org.openide.util.NbBundle;
26
27 /**
28  *
29  * @author Marian Petras
30  */

31 final class TestMethodNode extends AbstractNode {
32
33     /** */
34     private final Report.Testcase testcase;
35
36     /**
37      * Creates a new instance of TestcaseNode
38      */

39     TestMethodNode(final Report.Testcase testcase) {
40         super(testcase.trouble != null
41               ? new TestMethodNodeChildren(testcase)
42               : Children.LEAF);
43
44         this.testcase = testcase;
45
46         setDisplayName();
47         setIconBaseWithExtension(
48                 "org/netbeans/modules/junit/output/res/method.gif"); //NOI18N
49
}
50     
51     /**
52      */

53     private void setDisplayName() {
54         final int status = (testcase.trouble == null)
55                            ? 0
56                            : testcase.trouble.isError() ? 1 : 2;
57         
58         if ((status == 0) && (testcase.timeMillis < 0)) {
59             setDisplayName(testcase.name);
60             return;
61         }
62         
63         String JavaDoc[] noTimeKeys = new String JavaDoc[] {
64                                       null,
65                                       "MSG_TestMethodError", //NOI18N
66
"MSG_TestMethodFailed"}; //NOI18N
67
String JavaDoc[] timeKeys = new String JavaDoc[] {
68                                       "MSG_TestMethodPassed_time", //NOI18N
69
"MSG_TestMethodError_time", //NOI18N
70
"MSG_TestMethodFailed_time"}; //NOI18N
71
setDisplayName(
72                 testcase.timeMillis < 0
73                 ? NbBundle.getMessage(getClass(),
74                                       noTimeKeys[status],
75                                       testcase.name)
76                 : NbBundle.getMessage(getClass(),
77                                       timeKeys[status],
78                                       testcase.name,
79                                       new Float JavaDoc(testcase.timeMillis/1000f)));
80     }
81     
82     /**
83      */

84     public String JavaDoc getHtmlDisplayName() {
85         final int status = (testcase.trouble == null)
86                            ? 0
87                            : testcase.trouble.isError() ? 1 : 2;
88         String JavaDoc[] noTimeKeys = new String JavaDoc[] {
89                                       "MSG_TestMethodPassed_HTML", //NOI18N
90
"MSG_TestMethodError_HTML", //NOI18N
91
"MSG_TestMethodFailed_HTML"}; //NOI18N
92
String JavaDoc[] timeKeys = new String JavaDoc[] {
93                                       "MSG_TestMethodPassed_HTML_time", //NOI18N
94
"MSG_TestMethodError_HTML_time", //NOI18N
95
"MSG_TestMethodFailed_HTML_time"};//NOI18N
96

97         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(60);
98         buf.append(testcase.name);
99         buf.append("&nbsp;&nbsp;"); //NOI18N
100
buf.append("<font color='#"); //NOI18N
101
buf.append(testcase.trouble != null ? "FF0000'>" : "00CC00'>"); //NOI18N
102
buf.append(testcase.timeMillis < 0
103                    ? NbBundle.getMessage(getClass(),
104                                          noTimeKeys[status])
105                    : NbBundle.getMessage(getClass(),
106                                          timeKeys[status],
107                                          new Float JavaDoc(testcase.timeMillis/1000f)));
108         buf.append("</font>"); //NOI18N
109
return buf.toString();
110     }
111     
112     /**
113      */

114     public Action JavaDoc getPreferredAction() {
115         Report.Trouble trouble = testcase.trouble;
116         String JavaDoc callstackFrameInfo =
117                 ((trouble != null)
118                         && (trouble.stackTrace != null)
119                         && (trouble.stackTrace.length != 0))
120                 ? trouble.stackTrace[0]
121                 : null;
122         
123         return new JumpAction(this, callstackFrameInfo);
124     }
125     
126 }
127
Popular Tags