Refine search
private void validatePublicStaticVoidMethods( Class<? extends Annotation> annotation, Integer parameterCount, List<Throwable> errors) { List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation); for (FrameworkMethod fm : methods) { fm.validatePublicVoid(true, errors); if (parameterCount != null) { int methodParameterCount = fm.getMethod().getParameterTypes().length; if (methodParameterCount != 0 && methodParameterCount != parameterCount) { errors.add(new Exception("Method " + fm.getName() + "() should have 0 or " + parameterCount + " parameter(s)")); } } } }
public static <T extends Annotation> T locateAnnotation( Class<T> annotationClass, FrameworkMethod frameworkMethod, TestClass testClass) { T annotation = frameworkMethod.getAnnotation( annotationClass ); if ( annotation == null ) { annotation = testClass.getJavaClass().getAnnotation( annotationClass ); } return annotation; }
private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) { for (FrameworkMethod dataPointsMethod : fClass .getAnnotatedMethods(DataPoints.class)) { try { addMultiPointArrayValues(sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null)); } catch (Throwable e) { // ignore and move on } } }
@Override protected void invokeMethod(FrameworkMethod method) throws Throwable { int paramCount = method.getMethod().getParameterTypes().length; method.invokeExplosively(null, paramCount == 0 ? (Object[]) null : parameters); } }
@Override public boolean isShadowedBy(FrameworkMethod other) { if (!other.getName().equals(getName())) { return false; } if (other.getParameterTypes().length != getParameterTypes().length) { return false; } for (int i = 0; i < other.getParameterTypes().length; i++) { if (!other.getParameterTypes()[i].equals(getParameterTypes()[i])) { return false; } } return true; }
@Override protected void validateTestMethods(List<Throwable> errors) { for (FrameworkMethod each : computeTestMethods()) { if (each.getAnnotation(Theory.class) != null) { each.validatePublicVoid(false, errors); } else { each.validatePublicVoidNoArg(false, errors); } } }
UseDataProvider useDataProvider = testMethod.getAnnotation(UseDataProvider.class); DataProvider dataProvider = testMethod.getAnnotation(DataProvider.class); .getName(), useDataProvider.getClass().getSimpleName(), dataProvider.getClass().getSimpleName()))); testMethod.validatePublicVoidNoArg(false, errors); 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())));
@Override public String getDescription() throws CouldNotGenerateValueException { return method.getName(); } }
/** * Evaluates whether {@link FrameworkMethod}s are ignored based on the * {@link Ignore} annotation. */ @Override protected boolean isIgnored(FrameworkMethod child) { return child.getAnnotation(Ignore.class) != null; }
private static FrameworkMethod getParametersMethod(TestClass testClass, ClassLoader classLoader) throws Exception { List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Parameters.class); for (FrameworkMethod each : methods) { int modifiers = each.getMethod().getModifiers(); if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) { return getFrameworkMethodInClassLoader(each, classLoader); } } throw new Exception("No public static parameters method on class " + testClass.getName()); }
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")); } } }
@Override protected void validateTestMethods(List<Throwable> errors) { for (FrameworkMethod each : computeTestMethods()) { if (each.getAnnotation(Theory.class) != null) { each.validatePublicVoid(false, errors); each.validateNoTypeParametersOnArgs(errors); } else { each.validatePublicVoidNoArg(false, errors); } for (ParameterSignature signature : ParameterSignature.signatures(each.getMethod())) { ParametersSuppliedBy annotation = signature.findDeepAnnotation(ParametersSuppliedBy.class); if (annotation != null) { validateParameterSupplier(annotation.value(), 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())); }
Class bootstrappedTestClass = sandbox.bootstrappedClass(getTestClass().getJavaClass()); HelperTestRunner helperTestRunner = getHelperTestRunner(bootstrappedTestClass); helperTestRunner.frameworkMethod = method; try { bootstrappedMethod = bootstrappedTestClass.getMethod(method.getMethod().getName()); } catch (NoSuchMethodException e) { throw new RuntimeException(e); final Statement statement = helperTestRunner.methodBlock(new FrameworkMethod(bootstrappedMethod));
/** * Extract a nice test name representation for display * * @param frameworkMethod The test method. * * @return The display representation */ public static String extractTestName(FrameworkMethod frameworkMethod) { return frameworkMethod.getMethod().getDeclaringClass().getName() + '#' + frameworkMethod.getName(); }
private static void invokeAfterClass(final Class<?> clazz) throws Throwable { final TestClass testClass = new TestClass(clazz); final List<FrameworkMethod> afters = testClass.getAnnotatedMethods(AfterClass.class); for (FrameworkMethod after : afters) { after.invokeExplosively(null); } }
private static Exception parametersMethodReturnedWrongType( TestClass testClass, FrameworkMethod parametersMethod) throws Exception { String className = testClass.getName(); String methodName = parametersMethod.getName(); String message = MessageFormat.format( "{0}.{1}() must return an Iterable of arrays.", className, methodName); return new Exception(message); }
@Override public void evaluate() throws Throwable { runWithAssignment(Assignments.allUnassigned( testMethod.getMethod(), getTestClass())); //if this test method is not annotated with Theory, then no successes is a valid case boolean hasTheoryAnnotation = testMethod.getAnnotation(Theory.class) != null; if (successes == 0 && hasTheoryAnnotation) { Assert .fail("Never found parameters that satisfied method assumptions. Violated assumptions: " + fInvalidParameters); } }
private static void validateStateChangeMethods(TestClass testClass, final List<Throwable> errors) { getAnnotatedMethods(testClass, State.class).forEach(method -> { method.validatePublicVoid(false, errors); if (method.getMethod().getParameterCount() == 1 && !Map.class.isAssignableFrom(method.getMethod().getParameterTypes()[0])) { errors.add(new Exception("Method " + method.getName() + " should take only a single Map parameter")); } else if (method.getMethod().getParameterCount() > 1) { errors.add(new Exception("Method " + method.getName() + " should either take no parameters or a single Map parameter")); } }); }