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

The following examples show how to use org.junit.runners.model.FrameworkMethod#validatePublicVoidNoArg() . 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: 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 2
Source File: LoadTimeWeavableTestRunner.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * Adds to {@code errors} if any method in this class is annotated with
 * {@code annotation}, but:
 * <ul>
 * <li>is not public, or
 * <li>takes parameters, or
 * <li>returns something other than void, or
 * <li>is static (given {@code isStatic is false}), or
 * <li>is not static (given {@code isStatic is true}).
 */
protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation,
        boolean isStatic, List<Throwable> errors) {
    List<FrameworkMethod> methods = getOriginalTestClass().getAnnotatedMethods(annotation);

    for (FrameworkMethod eachTestMethod : methods) {
        eachTestMethod.validatePublicVoidNoArg(isStatic, errors);
    }
}