@Nonnull private List<TestCaseEvent> convertClassToTestCaseEvents(ClassDefItem classDefItem) { AnnotationDirectoryItem annotationDirectoryItem = classDefItem.getAnnotations(); if (annotationDirectoryItem == null) { return emptyList(); } List<TestCaseEvent> testCaseEvents = new ArrayList<>(); for (AnnotationDirectoryItem.MethodAnnotation method : annotationDirectoryItem.getMethodAnnotations()) { stream(method.annotationSet.getAnnotations()) .filter(annotation -> TEST_ANNOTATION.equals(stringType(annotation))) .map(annotation -> convertToTestCaseEvent(classDefItem, annotationDirectoryItem, method)) .forEach(testCaseEvents::add); } return testCaseEvents; }
private boolean isClassIgnored(AnnotationDirectoryItem annotationDirectoryItem) { AnnotationSetItem classAnnotations = annotationDirectoryItem.getClassAnnotations(); if (classAnnotations == null) { return false; } return containsAnnotation(IGNORE_ANNOTATION, classAnnotations.getAnnotations()); }
@Nonnull private TestCaseEvent convertToTestCaseEvent(ClassDefItem classDefItem, AnnotationDirectoryItem annotationDirectoryItem, AnnotationDirectoryItem.MethodAnnotation method) { String testMethod = method.method.getMethodName().getStringValue(); AnnotationItem[] annotations = method.annotationSet.getAnnotations(); String testClass = getClassName(classDefItem); boolean isIgnored = isClassIgnored(annotationDirectoryItem) || isMethodIgnored(annotations); List<String> permissionsToRevoke = getPermissionsToRevoke(annotations); Map<String, String> properties = getTestProperties(annotations); return testCaseEvent() .withTestClass(testClass) .withTestMethod(testMethod) .withIsIgnored(isIgnored) .withPermissionsToRevoke(permissionsToRevoke) .withProperties(properties) .build(); }