1 19 20 package org.netbeans.modules.junit.output; 21 22 import java.awt.EventQueue ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import org.openide.nodes.AbstractNode; 26 import org.openide.nodes.Children; 27 import org.openide.util.NbBundle; 28 29 33 final class RootNode extends AbstractNode { 34 35 36 static final String name = "JUnit results root node"; 38 39 static final int ALL_PASSED_ABSENT = 0; 40 41 static final int SOME_PASSED_ABSENT = 1; 42 43 static final int ALL_PASSED_DISPLAYED = 2; 44 45 47 private final RootNodeChildren children; 48 49 51 private volatile boolean filtered; 52 53 private volatile String 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 65 public RootNode(final boolean filtered) { 66 super(new RootNodeChildren(filtered)); 67 this.filtered = filtered; 68 children = (RootNodeChildren) getChildren(); 69 setName(name); setIconBaseWithExtension( 71 "org/netbeans/modules/junit/output/res/empty.gif"); } 73 74 76 void displayMessage(final String msg) { 77 assert EventQueue.isDispatchThread(); 78 79 80 81 this.message = msg; 82 updateDisplayName(); 83 } 84 85 93 void displaySuiteRunning(final String suiteName) { 94 assert EventQueue.isDispatchThread(); 95 96 97 98 children.displaySuiteRunning(suiteName); 99 } 100 101 103 TestsuiteNode displayReport(final Report report) { 104 assert EventQueue.isDispatchThread(); 105 106 107 108 updateStatistics(report); 109 updateDisplayName(); 110 return children.displayReport(report); 111 } 112 113 115 void displayReports(final Collection <Report> reports) { 116 assert EventQueue.isDispatchThread(); 117 118 119 120 for (Report report : reports) { 121 updateStatistics(report); 122 } 123 updateDisplayName(); 124 children.displayReports(reports); 125 } 126 127 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 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 155 private void updateDisplayName() { 156 assert EventQueue.isDispatchThread(); 157 158 159 160 final Class bundleRefClass = getClass(); 161 String msg; 162 163 if (totalTests == 0) { 164 msg = null; 165 } else if ((failures == 0) && (errors == 0)) { 166 msg = NbBundle.getMessage(bundleRefClass, 167 "MSG_TestsInfoAllOK", new Integer (totalTests)); 169 } else { 170 String passedTestsInfo = NbBundle.getMessage( 171 bundleRefClass, 172 "MSG_PassedTestsInfo", new Integer (totalTests - failures - errors)); 174 String failedTestsInfo = (failures == 0) 175 ? null 176 : NbBundle.getMessage( 177 bundleRefClass, 178 "MSG_FailedTestsInfo", new Integer (failures)); 180 String errorTestsInfo = (errors == 0) 181 ? null 182 : NbBundle.getMessage( 183 bundleRefClass, 184 "MSG_ErrorTestsInfo", new Integer (errors)); 186 if ((failedTestsInfo == null) || (errorTestsInfo == null)) { 187 msg = NbBundle.getMessage(bundleRefClass, 188 "MSG_TestsOneIssueType", passedTestsInfo, 190 failedTestsInfo != null 191 ? failedTestsInfo 192 : errorTestsInfo); 193 } else { 194 msg = NbBundle.getMessage(bundleRefClass, 195 "MSG_TestsFailErrIssues", 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"); break; 212 case ALL_PASSED_ABSENT: 213 msg += ' '; 214 msg += NbBundle.getMessage( 215 bundleRefClass, 216 "MSG_PassedNotDisplayed"); 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 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 |