(File cFile)
| 34 | } |
| 35 | } |
| 36 | @Override public void process(File cFile) { |
| 37 | try { |
| 38 | String cName = ClassNameFinder.thisClass( |
| 39 | Files.readAllBytes(cFile.toPath())); |
| 40 | if(!cName.startsWith("public:")) |
| 41 | return; |
| 42 | cName = cName.split(":")[1]; |
| 43 | if(!cName.contains(".")) |
| 44 | return; // Ignore unpackaged classes |
| 45 | testClass = Class.forName(cName); |
| 46 | } catch(IOException | ClassNotFoundException e) { |
| 47 | throw new RuntimeException(e); |
| 48 | } |
| 49 | TestMethods testMethods = new TestMethods(); |
| 50 | Method creator = null; |
| 51 | Method cleanup = null; |
| 52 | for(Method m : testClass.getDeclaredMethods()) { |
| 53 | testMethods.addIfTestMethod(m); |
| 54 | if(creator == null) |
| 55 | creator = checkForCreatorMethod(m); |
| 56 | if(cleanup == null) |
| 57 | cleanup = checkForCleanupMethod(m); |
| 58 | } |
| 59 | if(testMethods.size() > 0) { |
| 60 | if(creator == null) |
| 61 | try { |
| 62 | if(!Modifier.isPublic(testClass |
| 63 | .getDeclaredConstructor() |
| 64 | .getModifiers())) { |
| 65 | System.out.println("Error: " + testClass + |
| 66 | " zero-argument constructor must be public"); |
| 67 | System.exit(1); |
| 68 | } |
| 69 | } catch(NoSuchMethodException e) { |
| 70 | // Synthesized zero-argument constructor; OK |
| 71 | } |
| 72 | System.out.println(testClass.getName()); |
| 73 | } |
| 74 | for(Method m : testMethods) { |
| 75 | System.out.print(" . " + m.getName() + " "); |
| 76 | try { |
| 77 | Object testObject = createTestObject(creator); |
| 78 | boolean success = false; |
| 79 | try { |
| 80 | if(m.getReturnType().equals(boolean.class)) |
| 81 | success = (Boolean)m.invoke(testObject); |
| 82 | else { |
| 83 | m.invoke(testObject); |
| 84 | success = true; // If no assert fails |
| 85 | } |
| 86 | } catch(InvocationTargetException e) { |
| 87 | // Actual exception is inside e: |
| 88 | System.out.println(e.getCause()); |
| 89 | } |
| 90 | System.out.println(success ? "" : "(failed)"); |
| 91 | testsRun++; |
| 92 | if(!success) { |
| 93 | failures++; |
nothing calls this directly
no test coverage detected