private void validatePublicConstructor(List<Throwable> errors) { if (getTestClass().getJavaClass() != null) { errors.addAll(PUBLIC_CLASS_VALIDATOR.validateTestClass(getTestClass())); } }
protected void validateNoNonStaticInnerClass(List<Throwable> errors) { if (getTestClass().isANonStaticInnerClass()) { String gripe = "The inner class " + getTestClass().getName() + " is not static."; errors.add(new Exception(gripe)); } }
/** * Returns the methods that run tests. Default implementation returns all * methods annotated with {@code @Test} on this class and superclasses that * are not overridden. */ protected List<FrameworkMethod> computeTestMethods() { return getTestClass().getAnnotatedMethods(Test.class); }
/** * Returns a new fixture for running a test. Default implementation executes * the test class's no-argument constructor (validation should have ensured * one exists). */ protected Object createTest() throws Exception { return getTestClass().getOnlyConstructor().newInstance(); }
protected void validateNoNonStaticInnerClass(List<Throwable> errors) { if (getTestClass().isANonStaticInnerClass()) { String gripe = "The inner class " + getTestClass().getName() + " is not static."; errors.add(new Exception(gripe)); } }
/** * Returns the methods that run tests. Default implementation returns all * methods annotated with {@code @Test} on this class and superclasses that * are not overridden. */ protected List<FrameworkMethod> computeTestMethods() { return getTestClass().getAnnotatedMethods(Test.class); }
/** * @param target the test case instance * @return a list of MethodRules that should be applied when executing this * test */ protected List<org.junit.rules.MethodRule> rules(Object target) { return getTestClass().getAnnotatedFieldValues(target, Rule.class, org.junit.rules.MethodRule.class); }
/** * Returns a new fixture for running a test. Default implementation executes * the test class's no-argument constructor (validation should have ensured * one exists). */ protected Object createTest() throws Exception { return getTestClass().getOnlyConstructor().newInstance(); }
/** * @param target the test case instance * @return a list of TestRules that should be applied when executing this * test */ protected List<TestRule> getTestRules(Object target) { List<TestRule> result = getTestClass().getAnnotatedMethodValues(target, Rule.class, TestRule.class); result.addAll(getTestClass().getAnnotatedFieldValues(target, Rule.class, TestRule.class)); return result; }
protected void validateFields(List<Throwable> errors) { RULE_VALIDATOR.validate(getTestClass(), errors); }
private boolean hasOneConstructor() { return getTestClass().getJavaClass().getConstructors().length == 1; }
private void validateMethods(List<Throwable> errors) { RULE_METHOD_VALIDATOR.validate(getTestClass(), errors); }
/** * Adds to {@code errors} if the test class's single constructor takes * parameters (do not override) */ protected void validateZeroArgConstructor(List<Throwable> errors) { if (!getTestClass().isANonStaticInnerClass() && hasOneConstructor() && (getTestClass().getOnlyConstructor().getParameterTypes().length != 0)) { String gripe = "Test class should have exactly one public zero-argument constructor"; errors.add(new Exception(gripe)); } }
/** * Adds to {@code errors} if the test class's single constructor takes * parameters (do not override) */ protected void validateZeroArgConstructor(List<Throwable> errors) { if (!getTestClass().isANonStaticInnerClass() && hasOneConstructor() && (getTestClass().getOnlyConstructor().getParameterTypes().length != 0)) { String gripe = "Test class should have exactly one public zero-argument constructor"; errors.add(new Exception(gripe)); } }
/** * @param target the test case instance * @return a list of TestRules that should be applied when executing this * test */ protected List<TestRule> getTestRules(Object target) { RuleCollector<TestRule> collector = new RuleCollector<TestRule>(); getTestClass().collectAnnotatedMethodValues(target, Rule.class, TestRule.class, collector); getTestClass().collectAnnotatedFieldValues(target, Rule.class, TestRule.class, collector); return collector.result; }
/** * Returns a {@link Statement}: run all non-overridden {@code @Before} * methods on this class and superclasses before running {@code next}; if * any throws an Exception, stop execution and pass the exception on. */ protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods( Before.class); return befores.isEmpty() ? statement : new RunBefores(statement, befores, target); }
/** * @param target the test case instance * @return a list of MethodRules that should be applied when executing this * test */ protected List<MethodRule> rules(Object target) { RuleCollector<MethodRule> collector = new RuleCollector<MethodRule>(); getTestClass().collectAnnotatedMethodValues(target, Rule.class, MethodRule.class, collector); getTestClass().collectAnnotatedFieldValues(target, Rule.class, MethodRule.class, collector); return collector.result; }
/** * Returns a {@link Statement}: run all non-overridden {@code @After} * methods on this class and superclasses before running {@code next}; all * After methods are always executed: exceptions thrown by previous steps * are combined, if necessary, with exceptions from After methods into a * {@link MultipleFailureException}. */ protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods( After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, target); }
@Override protected Description describeChild(FrameworkMethod method) { Description description = methodDescriptions.get(method); if (description == null) { description = Description.createTestDescription(getTestClass().getJavaClass(), testName(method), method.getAnnotations()); methodDescriptions.putIfAbsent(method, description); } return description; }
@Override protected Description describeChild(FrameworkMethod method) { return Description.createTestDescription(getTestClass().getJavaClass(), testName(method), method.getAnnotations()); }