Java Code Examples for org.junit.runners.model.FrameworkMethod#validatePublicVoid()

The following examples show how to use org.junit.runners.model.FrameworkMethod#validatePublicVoid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertxUnitRunner.java    From vertx-unit with Apache License 2.0 6 votes vote down vote up
@Override
protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
  if (annotation == Test.class || annotation == Before.class || annotation == After.class ||
      annotation == BeforeClass.class || annotation == AfterClass.class) {
    List<FrameworkMethod> fMethods = getTestClass().getAnnotatedMethods(annotation);
    for (FrameworkMethod fMethod : fMethods) {
      fMethod.validatePublicVoid(isStatic, errors);
      try {
        validateTestMethod(fMethod);
      } catch (Exception e) {
        errors.add(e);
      }
    }
  } else {
    super.validatePublicVoidNoArgMethods(annotation, isStatic, errors);
  }
}
 
Example 2
Source File: TestValidator.java    From junit-dataprovider with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the given {@code testMethod} is a valid test method depending on the dataprovider relevant annotation
 * {@code @}{@link DataProvider} and {@code @}{@link UseDataProvider}. Adds {@link Exception}s to {@code errors} for
 * each invalid property. A normal test method must be is public, void instance method with no arguments. A data
 * provider test method must be is public and void instance method but have a least one argument.
 *
 * @param testMethod the test method to be validated
 * @param errors to be "returned" and thrown as {@link InitializationError}
 * @throws IllegalArgumentException if given {@code errors} is {@code null}
 */
public void validateTestMethod(FrameworkMethod testMethod, List<Throwable> errors) {
    checkNotNull(testMethod, "testMethod must not be null");
    checkNotNull(errors, "errors must not be null");

    UseDataProvider useDataProvider = testMethod.getAnnotation(UseDataProvider.class);
    DataProvider dataProvider = testMethod.getAnnotation(DataProvider.class);

    if (useDataProvider != null && dataProvider != null) {
        errors.add(new Exception(String.format("Method %s() should either have @%s or @%s annotation", testMethod
                .getName(), useDataProvider.getClass().getSimpleName(), dataProvider.getClass().getSimpleName())));

    } else if (useDataProvider == null && dataProvider == null) {
        testMethod.validatePublicVoidNoArg(false, errors);

    } else {
        testMethod.validatePublicVoid(false, errors);
        if (testMethod.getMethod().getParameterTypes().length <= 0) {
            errors.add(new Exception(String.format("Method %s() must have at least one argument for dataprovider",
                    testMethod.getName())));
        }
    }
}
 
Example 3
Source File: JQF.java    From JQF with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void validateFuzzMethods(List<Throwable> errors) {
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Fuzz.class)) {
        method.validatePublicVoid(false, errors);
        if (method.getAnnotation(Property.class) != null) {
            errors.add(new Exception("Method " + method.getName() +
                    " cannot have both @Property and @Fuzz annotations"));
        }
    }
}
 
Example 4
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private void validatePublicStaticVoidMethods(Class<? extends Annotation> annotation,
                                             List<Throwable> errors) {
    final List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation);
    for (FrameworkMethod eachTestMethod : methods) {
        eachTestMethod.validatePublicVoid(true, errors);
    }
}
 
Example 5
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private void validatePublicStaticVoidMethods(Class<? extends Annotation> annotation,
                                             List<Throwable> errors) {
    final List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation);
    for (FrameworkMethod eachTestMethod : methods) {
        eachTestMethod.validatePublicVoid(true, errors);
    }
}
 
Example 6
Source File: DesugarRunner.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * In replacement of {@link BlockJUnit4ClassRunner#validatePublicVoidNoArgMethods} for @Test
 * method signature validation.
 */
private void validatePublicVoidMethodsWithInjectableArgs(
    Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
  List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation);
  for (FrameworkMethod eachTestMethod : methods) {
    eachTestMethod.validatePublicVoid(isStatic, errors);
    validateInjectableParameters(eachTestMethod, errors);
    validateParameterValueSource(eachTestMethod, errors);
  }
}
 
Example 7
Source File: DatakernelRunner.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
	for (FrameworkMethod testMethod : getTestClass().getAnnotatedMethods(annotation)) {
		testMethod.validatePublicVoid(isStatic, errors);
	}
}
 
Example 8
Source File: EndToEndRunner.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Marks validation errors in errors if:
 *
 * <ul>
 *   <li>Any method marked by @Test is a not a public non-static void method.
 *   <li>Any method marked by @Test does not have exact args ({@link EndToEndTestDescriptor},
 *       {@link ProcessResult})
 * </ul>
 */
private void validateTestMethods(List<Throwable> errors) {
  List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Test.class);

  for (FrameworkMethod testMethod : methods) {
    testMethod.validatePublicVoid(false, errors);
    validateTestMethodArgs(testMethod, errors);
  }
}