/** * Returns a new {@code FrameworkMethod} for {@code method} */ public FrameworkMethod(Method method) { if (method == null) { throw new NullPointerException( "FrameworkMethod cannot be created without an underlying method."); } this.method = method; if (isPublic()) { // This method could be a public method in a package-scope base class try { method.setAccessible(true); } catch (SecurityException e) { // We may get an IllegalAccessException when we try to call the method } } }
/** * Adds to {@code errors} if this method: * <ul> * <li>is not public, 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}). * </ul> */ public void validatePublicVoid(boolean isStatic, List<Throwable> errors) { if (isStatic() != isStatic) { String state = isStatic ? "should" : "should not"; errors.add(new Exception("Method " + method.getName() + "() " + state + " be static")); } if (!isPublic()) { errors.add(new Exception("Method " + method.getName() + "() should be public")); } if (method.getReturnType() != Void.TYPE) { errors.add(new Exception("Method " + method.getName() + "() should be void")); } }
private static FrameworkMethod getParametersMethod(TestClass testClass) 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()); }
private FrameworkMethod getParametersMethod() throws Exception { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods( Parameters.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 List<FrameworkMethod> getParametersMethods() throws Exception { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods( Parameterized.Parameters.class); SortedMap<Integer, FrameworkMethod> sortedMethods = new TreeMap<Integer, FrameworkMethod>(); for (FrameworkMethod each : methods) { if (each.isPublic()) { if (!each.isStatic()) { if (getTestClass().getOnlyConstructor().getParameterCount() != 0) { throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters, it is not static and there is no parameter-less constructor!"); } } Order order = each.getAnnotation(Order.class); int value = order == null ? 0 : order.value(); FrameworkMethod prev = sortedMethods.put(value, each); if (prev != null) { throw new Exception(String.format("There are more methods annotated with @Parameters and @Order(value=%d): %s (%s) and %s (%s)", value, prev.getMethod(), prev.getAnnotation(Order.class), each.getMethod(), order)); } } else { throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters but it is not public!"); } } if (sortedMethods.isEmpty()) { throw new Exception("No public static parameters method on class " + getTestClass().getName()); } return new ArrayList<FrameworkMethod>(sortedMethods.values()); }
private static FrameworkMethod getAnnotatedMethod(ArtifactClassLoaderHolder artifactClassLoaderHolder, Class<?> isolatedTestClass, Class<? extends Annotation> annotationClass, String expectedParamType) throws ClassNotFoundException { TestClass testClass = new TestClass(isolatedTestClass); Class<? extends Annotation> artifactContextAwareAnn = (Class<? extends Annotation>) artifactClassLoaderHolder .loadClassWithATestRunnerClassLoader(annotationClass.getName()); List<FrameworkMethod> contextAwareMethods = testClass.getAnnotatedMethods(artifactContextAwareAnn); if (contextAwareMethods.size() != 1) { throw new IllegalStateException("Isolation tests need to have one method marked with annotation " + annotationClass.getName()); } final FrameworkMethod method = contextAwareMethods.get(0); if (!method.isStatic() || method.isPublic()) { throw new IllegalStateException("Method marked with annotation " + annotationClass.getName() + " should be private static and receive a parameter of type " + expectedParamType); } return method; }
private FrameworkMethod getParametersMethod() throws Exception { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods( Parameters.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(Parameters.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 InitializationError { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.class); for (FrameworkMethod each : methods) { if (each.isStatic() && each.isPublic()) { return each; } } throw new InitializationError("No public static parameters method on class " + getTestClass().getName()); }
private FrameworkMethod getParametersMethod() throws Exception { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.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( Parameters.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(Parameters.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( Parameters.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()); }
private FrameworkMethod getParametersMethod() throws Exception { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.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( Parameters.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 = 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()); }
private FrameworkMethod getParametersMethod() throws InitializationError { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.class); for (FrameworkMethod each : methods) { if (each.isStatic() && each.isPublic()) { return each; } } throw new InitializationError("No public static parameters method on class " + getTestClass().getName()); }
private FrameworkMethod getParametersMethod() throws InitializationError { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.class); for (FrameworkMethod each : methods) { if (each.isStatic() && each.isPublic()) { return each; } } throw new InitializationError("No public static parameters method on class " + getTestClass().getName()); }
private FrameworkMethod getParametersMethod() throws InitializationError { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameters.class); for (FrameworkMethod each : methods) { if (each.isStatic() && each.isPublic()) { return each; } } throw new InitializationError("No public static parameters method on class " + getTestClass().getName()); }