AssumptionViolationRunner(TestClass testClass, String methodName, AssumptionViolatedException exception) { this.description = Description .createTestDescription(testClass.getJavaClass(), methodName + "() assumption violation"); this.exception = exception; }
private boolean hasOneConstructor() { return getTestClass().getJavaClass().getConstructors().length == 1; }
private void validateDataPointFields(List<Throwable> errors) { Field[] fields = getTestClass().getJavaClass().getDeclaredFields(); for (Field field : fields) { if (field.getAnnotation(DataPoint.class) == null && field.getAnnotation(DataPoints.class) == null) { continue; } if (!Modifier.isStatic(field.getModifiers())) { errors.add(new Error("DataPoint field " + field.getName() + " must be static")); } if (!Modifier.isPublic(field.getModifiers())) { errors.add(new Error("DataPoint field " + field.getName() + " must be public")); } } }
private void validateDataPointMethods(List<Throwable> errors) { Method[] methods = getTestClass().getJavaClass().getDeclaredMethods(); for (Method method : methods) { if (method.getAnnotation(DataPoint.class) == null && method.getAnnotation(DataPoints.class) == null) { continue; } if (!Modifier.isStatic(method.getModifiers())) { errors.add(new Error("DataPoint method " + method.getName() + " must be static")); } if (!Modifier.isPublic(method.getModifiers())) { errors.add(new Error("DataPoint method " + method.getName() + " must be public")); } } }
@Override protected Object createTest() throws Exception { return TestClassRunnerForParameters.this.createTestInstance( getTestClass().getJavaClass()); }
private void validate() throws InitializationError { List<Throwable> errors = new ArrayList<Throwable>(); collectInitializationErrors(errors); if (!errors.isEmpty()) { throw new InvalidTestClassError(testClass.getJavaClass(), errors); } }
/** * Return {@code true} if {@link Ignore @Ignore} is present for the supplied * {@linkplain FrameworkMethod test method} or if the test method is disabled * via {@code @IfProfileValue}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) */ protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { Method method = frameworkMethod.getMethod(); return (method.isAnnotationPresent(Ignore.class) || !ProfileValueUtils.isTestEnabledInThisEnvironment(method, getTestClass().getJavaClass())); }
/** * Return a description suitable for an ignored test class if the test is * disabled via {@code @IfProfileValue} at the class-level, and * otherwise delegate to the parent implementation. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) */ @Override public Description getDescription() { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(getTestClass().getJavaClass())) { return Description.createSuiteDescription(getTestClass().getJavaClass()); } return super.getDescription(); }
@Nonnull protected Class<?>[] getExtraShadows(FrameworkMethod method) { List<Class<?>> shadowClasses = new ArrayList<>(); addShadows(shadowClasses, getTestClass().getJavaClass().getAnnotation(SandboxConfig.class)); addShadows(shadowClasses, method.getAnnotation(SandboxConfig.class)); return shadowClasses.toArray(new Class[shadowClasses.size()]); }
private void applyValidators(List<Throwable> errors) { if (getTestClass().getJavaClass() != null) { for (TestClassValidator each : VALIDATORS) { errors.addAll(each.validateTestClass(getTestClass())); } } }
private void validatePublicConstructor(List<Throwable> errors) { if (getTestClass().getJavaClass() != null) { errors.addAll(PUBLIC_CLASS_VALIDATOR.validateTestClass(getTestClass())); } }
private void validateBeforeParamAndAfterParamMethods(Integer parameterCount) throws InvalidTestClassError { List<Throwable> errors = new ArrayList<Throwable>(); validatePublicStaticVoidMethods(Parameterized.BeforeParam.class, parameterCount, errors); validatePublicStaticVoidMethods(Parameterized.AfterParam.class, parameterCount, errors); if (!errors.isEmpty()) { throw new InvalidTestClassError(getTestClass().getJavaClass(), errors); } }
@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; }
private void createRunnersForParameters(Iterable<Object[]> allParameters, String namePattern) throws Exception { int i = 0; for (Object[] parametersOfSingleTest : allParameters) { String name = nameFor(namePattern, i, parametersOfSingleTest); CustomRunnerForParameters runner = new CustomRunnerForParameters( getTestClass().getJavaClass(), parametersOfSingleTest, name); runners.add(runner); ++i; } }
@Override protected Description describeChild(FrameworkMethod method) { return Description.createTestDescription(getTestClass().getJavaClass(), testName(method), method.getAnnotations()); }
/** * Check whether the test is enabled in the current execution environment. * <p>This prevents classes with a non-matching {@code @IfProfileValue} * annotation from running altogether, even skipping the execution of * {@code prepareTestInstance()} methods in {@code TestExecutionListeners}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) * @see org.springframework.test.annotation.IfProfileValue * @see org.springframework.test.context.TestExecutionListener */ @Override public void run(RunNotifier notifier) { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(getTestClass().getJavaClass())) { notifier.fireTestIgnored(getDescription()); return; } super.run(notifier); }
@Override protected Description describeChild(Path child) { return Description.createTestDescription(getTestClass().getJavaClass(), child.toString()); }
@Override protected Description describeChild(FileSet child) { return Description.createTestDescription(getTestClass().getJavaClass(), child.name); }
@Override protected List<FrameworkMethod> computeTestMethods() { return JUnit4ZKTestRunner.computeTestMethodsForClass(getTestClass().getJavaClass(), super.computeTestMethods()); }
@Override protected List<FrameworkMethod> computeTestMethods() { return computeTestMethodsForClass(getTestClass().getJavaClass(), super.computeTestMethods()); }