private void resolveContainedMethods(TestDescriptor containerDescriptor, Class<?> testClass) { List<Method> testMethodCandidates = findMethods(testClass, ReflectionUtils::isNotPrivate); testMethodCandidates.forEach(method -> resolve(method, containerDescriptor)); }
private static Method findFactoryMethod(Class<?> targetType) { List<Method> factoryMethods = findMethods(targetType, new IsFactoryMethod(targetType), BOTTOM_UP); if (factoryMethods.size() == 1) { return factoryMethods.get(0); } return null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T initialize(AnnotatedElement annotatedElement, T instance) { if (instance instanceof AnnotationConsumer) { Method method = findMethods(instance.getClass(), isAnnotationConsumerAcceptMethod, BOTTOM_UP).get(0); Class<? extends Annotation> annotationType = (Class<? extends Annotation>) method.getParameterTypes()[0]; Annotation annotation = AnnotationUtils.findAnnotation(annotatedElement, annotationType) // .orElseThrow(() -> new JUnitException(instance.getClass().getName() + " must be used with an annotation of type " + annotationType.getName())); initializeAnnotationConsumer((AnnotationConsumer) instance, annotation); } return instance; }
private static MethodSource toMethodSource(Class<?> testClass, String methodName) { if (methodName.contains("[") && methodName.endsWith("]")) { // special case for parameterized tests return toMethodSource(testClass, methodName.substring(0, methodName.indexOf("["))); } else { List<Method> methods = findMethods(testClass, where(Method::getName, isEqual(methodName))); return (methods.size() == 1) ? MethodSource.from(testClass, getOnlyElement(methods)) : null; } }
private List<Method> findAnnotatedMethods(Object testInstance) { Predicate<Method> isRuleMethod = method -> isAnnotated(method, Rule.class); Predicate<Method> hasCorrectReturnType = method -> TestRule.class.isAssignableFrom(method.getReturnType()); return findMethods(testInstance.getClass(), isRuleMethod.and(hasCorrectReturnType)); }
private void resolveContainedMethods(TestDescriptor containerDescriptor, Class<?> testClass, BiConsumer<AnnotatedElement, TestDescriptor> fixtureResolver) { List<Method> benchmarkMethodCandidates = ReflectionUtils.findMethods(testClass, IsBenchmarkMethod.INSTANCE); benchmarkMethodCandidates.forEach(it -> { Set<TestDescriptor> methodDescriptors = resolve(it, containerDescriptor); methodDescriptors.forEach(methodDescriptor -> fixtureResolver.accept(it, methodDescriptor)); }); }
@Override protected List<Method> findRuleAnnotatedMembers(Object testInstance) { Predicate<Method> isRuleMethod = method -> isAnnotated(method, Rule.class); Predicate<Method> hasCorrectReturnType = method -> method.getReturnType().isAssignableFrom(getRuleType()); return findMethods(testInstance.getClass(), isRuleMethod.and(hasCorrectReturnType)); }