1 19 20 package org.netbeans.modules.junit.output; 21 22 import javax.swing.Action ; 23 import org.openide.nodes.AbstractNode; 24 import org.openide.nodes.Children; 25 import org.openide.util.NbBundle; 26 27 31 final class TestMethodNode extends AbstractNode { 32 33 34 private final Report.Testcase testcase; 35 36 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"); } 50 51 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 [] noTimeKeys = new String [] { 64 null, 65 "MSG_TestMethodError", "MSG_TestMethodFailed"}; String [] timeKeys = new String [] { 68 "MSG_TestMethodPassed_time", "MSG_TestMethodError_time", "MSG_TestMethodFailed_time"}; 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 (testcase.timeMillis/1000f))); 80 } 81 82 84 public String getHtmlDisplayName() { 85 final int status = (testcase.trouble == null) 86 ? 0 87 : testcase.trouble.isError() ? 1 : 2; 88 String [] noTimeKeys = new String [] { 89 "MSG_TestMethodPassed_HTML", "MSG_TestMethodError_HTML", "MSG_TestMethodFailed_HTML"}; String [] timeKeys = new String [] { 93 "MSG_TestMethodPassed_HTML_time", "MSG_TestMethodError_HTML_time", "MSG_TestMethodFailed_HTML_time"}; 97 StringBuffer buf = new StringBuffer (60); 98 buf.append(testcase.name); 99 buf.append(" "); buf.append("<font color='#"); buf.append(testcase.trouble != null ? "FF0000'>" : "00CC00'>"); buf.append(testcase.timeMillis < 0 103 ? NbBundle.getMessage(getClass(), 104 noTimeKeys[status]) 105 : NbBundle.getMessage(getClass(), 106 timeKeys[status], 107 new Float (testcase.timeMillis/1000f))); 108 buf.append("</font>"); return buf.toString(); 110 } 111 112 114 public Action getPreferredAction() { 115 Report.Trouble trouble = testcase.trouble; 116 String 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 |