protected Annotation[] classAnnotations() { return testClass.getJavaClass().getAnnotations(); }
public JUnit4ClassRunner(Class<?> klass) throws InitializationError { testClass = new TestClass(klass); testMethods = getTestMethods(); validate(); }
List<Method> getBefores() { return testClass.getAnnotatedMethods(Before.class); }
public List<Method> getAnnotatedMethods(Class<? extends Annotation> annotationClass) { List<Method> results = new ArrayList<Method>(); for (Class<?> eachClass : getSuperClasses(klass)) { Method[] methods = MethodSorter.getDeclaredMethods(eachClass); for (Method eachMethod : methods) { Annotation annotation = eachMethod.getAnnotation(annotationClass); if (annotation != null && !isShadowed(eachMethod, results)) { results.add(eachMethod); } } } if (runsTopToBottom(annotationClass)) { Collections.reverse(results); } return results; }
public void validateNoArgConstructor() { try { testClass.getConstructor(); } catch (Exception e) { errors.add(new Exception("Test class should have public zero-argument constructor", e)); } }
protected String getName() { return getTestClass().getName(); }
private boolean isShadowed(Method method, List<Method> results) { for (Method each : results) { if (isShadowed(method, each)) { return true; } } return false; }
private void runAfters() { List<Method> afters = testClass.getAfters(); for (Method after : afters) { try { after.invoke(null); } catch (InvocationTargetException e) { addFailure(e.getTargetException()); } catch (Throwable e) { addFailure(e); // Untested, but seems impossible } } } }
protected List<Method> getTestMethods() { return testClass.getTestMethods(); }
private void runBefores() throws FailedBefore { try { try { List<Method> befores = testClass.getBefores(); for (Method before : befores) { before.invoke(null); } } catch (InvocationTargetException e) { throw e.getTargetException(); } } catch (AssumptionViolatedException e) { throw new FailedBefore(); } catch (Throwable e) { addFailure(e); throw new FailedBefore(); } }
public List<Method> getAnnotatedMethods(Class<? extends Annotation> annotationClass) { List<Method> results = new ArrayList<Method>(); for (Class<?> eachClass : getSuperClasses(fClass)) { Method[] methods = MethodSorter.getDeclaredMethods(eachClass); for (Method eachMethod : methods) { Annotation annotation = eachMethod.getAnnotation(annotationClass); if (annotation != null && !isShadowed(eachMethod, results)) { results.add(eachMethod); } } } if (runsTopToBottom(annotationClass)) { Collections.reverse(results); } return results; }
public void validateNoArgConstructor() { try { fTestClass.getConstructor(); } catch (Exception e) { fErrors.add(new Exception("Test class should have public zero-argument constructor", e)); } }
protected String getName() { return getTestClass().getName(); }
private boolean isShadowed(Method method, List<Method> results) { for (Method each : results) { if (isShadowed(method, each)) { return true; } } return false; }
private void runAfters() { List<Method> afters = fTestClass.getAfters(); for (Method after : afters) { try { after.invoke(null); } catch (InvocationTargetException e) { addFailure(e.getTargetException()); } catch (Throwable e) { addFailure(e); // Untested, but seems impossible } } } }
protected List<Method> getTestMethods() { return fTestClass.getTestMethods(); }
private void runBefores() throws FailedBefore { try { try { List<Method> befores = fTestClass.getBefores(); for (Method before : befores) { before.invoke(null); } } catch (InvocationTargetException e) { throw e.getTargetException(); } } catch (org.junit.internal.AssumptionViolatedException e) { throw new FailedBefore(); } catch (Throwable e) { addFailure(e); throw new FailedBefore(); } }
public List<Method> getAnnotatedMethods(Class<? extends Annotation> annotationClass) { List<Method> results = new ArrayList<Method>(); for (Class<?> eachClass : getSuperClasses(fClass)) { Method[] methods = MethodSorter.getDeclaredMethods(eachClass); for (Method eachMethod : methods) { Annotation annotation = eachMethod.getAnnotation(annotationClass); if (annotation != null && !isShadowed(eachMethod, results)) { results.add(eachMethod); } } } if (runsTopToBottom(annotationClass)) { Collections.reverse(results); } return results; }
protected Annotation[] classAnnotations() { return fTestClass.getJavaClass().getAnnotations(); }
List<Method> getBefores() { return getAnnotatedMethods(BeforeClass.class); }