public static void main(String[] args) throws Exception { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); // Enable asserts new ProcessFiles(new AtUnit(), "class").start(args); if (failures == 0) Print.print("OK (" + testsRun + " tests)"); else { Print.print("(" + testsRun + " tests)"); Print.print("\n>>> " + failures + " FAILURE" + (failures > 1 ? "S" : "") + " <<<"); for (String failed : failedTests) Print.print(" " + failed); } }
public void process(File cFile) { try { String cName = ClassNameFinder.thisClass(BinaryFile.read(cFile)); if (!cName.contains("")) return; // Ignore unpackaged classes testClass = Class.forName(cName); } catch (Exception e) { throw new RuntimeException(e); } TestMethods testMethods = new TestMethods(); Method creator = null; Method cleanup = null; for (Method m : testClass.getDeclaredMethods()) { testMethods.addIfTestMethod(m); if (creator == null) creator = checkForCreatorMethod(m); if (cleanup == null) cleanup = checkForCleanupMethod(m); } if (testMethods.size() > 0) { if (creator == null) try { if (!Modifier.isPublic(testClass.getDeclaredConstructor().getModifiers())) { Print.print("Error: " + testClass + " default constructor must be public"); System.exit(1); } } catch (NoSuchMethodException e) { // Synthesized default constructor; OK } Print.print(testClass.getName()); } for (Method m : testMethods) { Print.printnb(" . " + m.getName() + " "); try { Object testObject = createTestObject(creator); boolean success = false; try { if (m.getReturnType().equals(boolean.class)) success = (Boolean) m.invoke(testObject); else { m.invoke(testObject); success = true; // If no assert fails } } catch (InvocationTargetException e) { // Actual exception is inside e: Print.print(e.getCause()); } Print.print(success ? "" : "(failed)"); testsRun++; if (!success) { failures++; failedTests.add(testClass.getName() + ": " + m.getName()); } if (cleanup != null) cleanup.invoke(testObject, testObject); } catch (Exception e) { throw new RuntimeException(e); } } }
public Entry getReferencedEntry() { Entry entry = getRuntimeEntry(this.getKey()); if (entry == null) { Print.logStackTrace("Entry reference not found: " + this.getKey()); } return entry; }
/** ** ActionListener interface execution ** @param ae The ActionEvent */ public void actionPerformed(ActionEvent ae) { try { this.invoke(); } catch (Throwable t) { // trap any method invocation error Print.logError("'invoke' error " + t); } }
/** ** Runs this MethodAction now */ public void run() { try { this.invoke(); } catch (Throwable t) { // trap any method invocation error Print.logError("'invoke' error " + t); } }
public Entry getRealEntry() { if (this.dft instanceof EntryReference) { Entry entry = null; if (this.ref > 0) { Print.logStackTrace("Cyclical EntryReference: " + this.getKey()); entry = NullEntry; } else { this.ref++; try { EntryReference entryRef = (EntryReference) this.dft; Entry nextEntry = entryRef.getReferencedEntry(); // <-- will display error, if not found entry = (nextEntry != null) ? nextEntry.getRealEntry() : NullEntry; } finally { this.ref--; } } return entry; } else { return this; } }