org.junit.runners.model.FrameworkMethod#isPublic()源码实例Demo

下面列出了org.junit.runners.model.FrameworkMethod#isPublic() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openCypher   文件: ParameterTest.java
public Runner( Class<?> klass ) throws Throwable
{
    super( klass, emptyList() );
    List<FrameworkMethod> parameters = getTestClass().getAnnotatedMethods( Test.class );
    List<Throwable> errors = null;
    for ( FrameworkMethod parameter : parameters )
    {
        if ( !(parameter.isPublic() && parameter.isStatic()) )
        {
            if ( errors == null )
            {
                errors = new ArrayList<>();
            }
            errors.add( new IllegalStateException(
                    "@Test method " + parameter.getName() + " should be public and static" ) );
        }
    }
    if ( errors != null )
    {
        throw new InitializationError( errors );
    }
    this.runners = createRunners( parameters );
}
 
/**
 * {@link ParameterizedBeforeClass}が設定されているフィールドをチェックします。
 * 
 * @param errors エラーのリスト。チェックした結果エラーがあった場合、このリストに追加される
 */
protected void validateParameterizedBeforeClass(List<Throwable> errors) {
	for (FrameworkMethod method : getTestClass().getAnnotatedMethods(ParameterizedBeforeClass.class)) {
		if (!method.isStatic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be static"));
		}
		if (!method.isPublic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be public"));
		}
		// このメソッドはコンストラクタのsuper内部で実行されるため、パラメーター数の取得ができない
		//			if (method.getMethod().getParameterTypes().length != parameters.length) {
		//				errors.add(new Exception(
		//						"Method " + method.getName() + "() should have " + parameters.length + " parameters"));
		//			}
		if (method.getType() != Void.TYPE) {
			errors.add(new Exception("Method " + method.getName() + "() should be void"));
		}
	}
}
 
/**
 * {@link ParameterizedAfterClass}が設定されているフィールドをチェックします。
 * 
 * @param errors エラーのリスト。チェックした結果エラーがあった場合、このリストに追加される
 */
protected void validateParameterizedAfterClass(List<Throwable> errors) {
	for (FrameworkMethod method : getTestClass().getAnnotatedMethods(ParameterizedAfterClass.class)) {
		if (!method.isStatic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be static"));
		}
		if (!method.isPublic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be public"));
		}
		// このメソッドはコンストラクタのsuper内部で実行されるため、パラメーター数の取得ができない
		//			if (method.getMethod().getParameterTypes().length != parameters.length) {
		//				errors.add(new Exception(
		//						"Method " + method.getName() + "() should have " + parameters.length + " parameters"));
		//			}
		if (method.getType() != Void.TYPE) {
			errors.add(new Exception("Method " + method.getName() + "() should be void"));
		}
	}
}
 
源代码4 项目: htmlunit   文件: BrowserParameterizedRunner.java
private FrameworkMethod getParametersMethod() throws Exception {
    final List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(
            Parameters.class);
    for (final FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + getTestClass().getName());
}
 
源代码5 项目: n4js   文件: XtextParametrizedRunner.java
private FrameworkMethod getAnnotatedPublicStaticMethod(Class<? extends Annotation> anno) {
	List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(anno);
	for (FrameworkMethod each : methods) {
		if (each.isStatic() && each.isPublic()) {
			return each;
		}
	}
	return null;
}
 
源代码6 项目: registry   文件: CustomParameterizedRunner.java
private FrameworkMethod getParametersMethod() throws Exception {
    List<FrameworkMethod> methods = testClass
            .getAnnotatedMethods(Parameters.class);
    for (FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + testClass.getName());
}
 
源代码7 项目: registry   文件: CustomParameterizedRunner.java
private FrameworkMethod getParametersMethod() throws Exception {
    List<FrameworkMethod> methods = testClass
            .getAnnotatedMethods(Parameters.class);
    for (FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + testClass.getName());
}
 
/**
 * {@link ParameterizedClassRule}が設定されているフィールドまたはメソッドをチェックします。
 * 
 * @param errors エラーのリスト。チェックした結果エラーがあった場合、このリストに追加される
 */
protected void validateParameterizedClassRules(List<Throwable> errors) {
	for (FrameworkMethod method : getTestClass().getAnnotatedMethods(ParameterizedClassRule.class)) {
		if (!method.isStatic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be static"));
		}
		if (!method.isPublic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be public"));
		}
		if (method.getMethod().getParameterTypes().length != 0) {
			errors.add(new Exception("Method " + method.getName() + "() should have no parameters"));
		}
		if (!ParameterizedTestRule.class.isAssignableFrom(method.getType())) {
			errors.add(new Exception("Method " + method.getName()
					+ "() must return an implementation of ParameterizedTestRule"));
		}
	}

	for (FrameworkField field : getTestClass().getAnnotatedFields(ParameterizedClassRule.class)) {
		if (!field.isStatic()) {
			errors.add(new Exception("Field " + field.getName() + " should be static"));
		}
		if (!field.isPublic()) {
			errors.add(new Exception("Field " + field.getName() + " should be public"));
		}
		if (!ParameterizedTestRule.class.isAssignableFrom(field.getType())) {
			errors.add(new Exception("Field " + field.getName() + " must implement ParameterizedTestRule"));
		}
	}
}
 
源代码9 项目: wildfly-core   文件: WildflyTestRunner.java
private FrameworkMethod findParametersMethod(final TestClass testClass) {
    final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Parameters.class);
    if (methods.size() > 1) {
        throw new RuntimeException(String.format("More than one method was annotated with @%s: %s",
                Parameters.class.getSimpleName(), methods));
    } else if (methods.isEmpty()) {
        return null;
    }
    final FrameworkMethod method = methods.get(0);
    if (method.isPublic() && method.isStatic() && Collection.class.isAssignableFrom(method.getReturnType())) {
        return method;
    }
    throw new RuntimeException(String.format("Method %s must be public, static and have a return type assignable to Collection<Object>.",
            method.getName()));
}
 
源代码10 项目: wildfly-core   文件: OldVersionTestRunner.java
private FrameworkMethod getParametersMethod() throws Exception {
    List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(
            OldVersionParameter.class);
    for (FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + getTestClass().getName());
}
 
private FrameworkMethod getParametersMethod() throws Exception {
    List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(
            TransformersParameter.class);
    for (FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + getTestClass().getName());
}
 
源代码12 项目: neodymium-library   文件: ParameterStatement.java
@SuppressWarnings("unchecked")
@Override
public List<Object> createIterationData(TestClass testClass, FrameworkMethod method) throws Exception
{
    List<FrameworkMethod> parametersMethods = testClass.getAnnotatedMethods(Parameters.class);
    Iterable<Object> parameter = null;

    for (FrameworkMethod parametersMethod : parametersMethods)
    {
        if (parametersMethod.isPublic() && parametersMethod.isStatic())
        {
            // take the first public static method. invoke it and use the result as parameter
            try
            {
                Object parametersResult = parametersMethod.invokeExplosively(null);
                if (parametersResult instanceof Iterable)
                {
                    parameter = (Iterable<Object>) parametersResult;
                }
                else if (parametersResult instanceof Object[])
                {
                    parameter = Arrays.asList((Object[]) parametersResult);
                }
                else
                {
                    String msg = MessageFormat.format("{0}.{1}() must return an Iterable of arrays.",
                                                      testClass.getJavaClass().getName(), parametersMethod.getName());
                    throw new Exception(msg);
                }
                break;
            }
            catch (Throwable e)
            {
                throw new RuntimeException(e);
            }
        }
    }

    if (!parametersMethods.isEmpty() && parameter == null)
    {
        throw new Exception("No public static parameters method on class " + testClass.getJavaClass().getCanonicalName());
    }

    List<FrameworkField> parameterFrameworkFields = testClass.getAnnotatedFields(Parameter.class);
    LOGGER.debug("Found " + parameterFrameworkFields.size() + " parameter fields");

    List<Object> iterations = new LinkedList<>();

    if (parameter != null)
    {
        int parameterSetCounter = 0;
        for (Object para : parameter)
        {
            Object[] p;
            if (para instanceof Object[])
            {
                p = (Object[]) para;
            }
            else
            {
                p = new Object[]
                {
                  para
                };
            }

            iterations.add(new ParameterStatementData(parameterSetCounter, p, parameterFrameworkFields));
            parameterSetCounter++;
        }
    }

    return iterations;
}
 
源代码13 项目: j2cl   文件: AsyncTestRunner.java
private void validateTestMethod(
    boolean isStatic, List<Throwable> errors, FrameworkMethod testMethod) {
  Class<?> returnType = testMethod.getReturnType();

  // taken from FrameworkMethod.validatePublicVoid
  if (testMethod.isStatic() != isStatic) {
    String state = isStatic ? "should" : "should not";
    errors.add(makeError("Method %s() " + state + " be static", testMethod));
  }
  if (!testMethod.isPublic()) {
    errors.add(makeError("Method %s() should be public", testMethod));
  }

  if (returnType == Void.TYPE) {
    return;
  }

  if (returnType == ListenableFuture.class) {
    return;
  }

  try {
    getPromiseType(returnType);
  } catch (InvalidTypeException e) {
    errors.add(makeError(e.getMessage()));
    return;
  }

  Test testAnnotation = testMethod.getAnnotation(Test.class);
  // Make sure we have a value greater than zero for test timeout
  if (getTimeout(testMethod) <= 0) {
    errors.add(
        makeError(ErrorMessage.ASYNC_HAS_NO_TIMEOUT.format(testMethod.getMethod().getName())));
  }

  if (testAnnotation != null && !testAnnotation.expected().equals(Test.None.class)) {
    errors.add(
        makeError(
            ErrorMessage.ASYNC_HAS_EXPECTED_EXCEPTION.format(testMethod.getMethod().getName())));
  }
}