1 19 20 package org.netbeans.modules.junit; 21 22 import java.util.MissingResourceException ; 23 import java.util.ResourceBundle ; 24 import org.openide.ErrorManager; 25 import org.openide.util.NbBundle; 26 27 33 final class TestabilityResult { 34 private long reason; 36 37 public static final TestabilityResult OK = new TestabilityResult(0); 39 public static final TestabilityResult PACKAGE_PRIVATE_CLASS = new TestabilityResult(1); 40 public static final TestabilityResult NO_TESTEABLE_METHODS = new TestabilityResult(2); 41 public static final TestabilityResult TEST_CLASS = new TestabilityResult(4); 42 public static final TestabilityResult ABSTRACT_CLASS = new TestabilityResult(8); 43 public static final TestabilityResult NONSTATIC_INNER_CLASS = new TestabilityResult(16); 44 public static final TestabilityResult EXCEPTION_CLASS = new TestabilityResult(32); 45 public static final TestabilityResult PRIVATE_CLASS = new TestabilityResult(64); 46 47 48 private static final String [] reasonBundleKeys = { 50 "TestabilityResult_PkgPrivate", 51 "TestabilityResult_NoTestableMethods", 52 "TestabilityResult_TestClass", 53 "TestabilityResult_AbstractClass", 54 "TestabilityResult_NonstaticInnerClass", 55 "TestabilityResult_ExceptionClass", 56 "TestabilityResult_Private"}; 57 58 private TestabilityResult(long reason) { 59 this.reason = reason; 60 } 61 62 75 public static TestabilityResult combine(TestabilityResult lhs, TestabilityResult rhs) { 76 return new TestabilityResult(lhs.reason | rhs.reason); 77 } 78 79 83 public boolean isTestable() { 84 return reason == 0; 85 } 86 87 91 public boolean isFailed() { 92 return reason != 0; 93 } 94 95 100 public String getReason() { 101 return getReason(", ", ", "); } 103 104 108 public String toString() { 109 return getReason(", ", ", "); } 111 112 123 public String getReason(String separ, String terminalSepar) { 124 try { 125 ResourceBundle bundle = NbBundle.getBundle(TestCreator.class); 126 if (reason == 0) { 127 return bundle.getString("TestabilityResult_OK"); } else { 129 String str = ""; boolean lastPrep = true; 131 for (long i = 0, r = reason; r > 0; r >>= 1, i++) { 132 if ((r & 1) != 0) { 133 if (str.length() > 0) { 134 if (lastPrep) { 135 str = terminalSepar + str; 136 lastPrep = false; 137 } else { 138 str = separ + str; 139 } 140 } 141 str = bundle.getString(reasonBundleKeys[(int)i]) + str; 142 } 143 } 144 return str; 145 } 146 } catch (MissingResourceException ex) { 147 ErrorManager.getDefault().notify(ex); 148 return ""; 149 } 150 } 151 152 156 static final class SkippedClass { 157 final String clsName; 158 final TestabilityResult reason; 159 SkippedClass(String clsName, 160 TestabilityResult reason) { 161 this.clsName = clsName; 162 this.reason = reason; 163 } 164 } 165 166 } 167 | Popular Tags |