Skip to content

Commit

Permalink
Adding new WithTesResource annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
edeandrea committed Jun 24, 2024
1 parent e48f061 commit c8df67f
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import io.smallrye.config.SmallRyeConfigProviderResolver;

public class TestResourceManager implements Closeable {

private static final DotName QUARKUS_TEST_RESOURCE = DotName.createSimple(QuarkusTestResource.class);
private static final DotName WITH_TEST_RESOURCE = DotName.createSimple(WithTestResource.class);
public static final String CLOSEABLE_NAME = TestResourceManager.class.getName() + ".closeable";

private final List<TestResourceEntry> sequentialTestResourceEntries;
Expand Down Expand Up @@ -316,8 +317,7 @@ private Set<TestResourceClassEntry> getUniqueTestResourceClassEntries(Path testC
isParallel = parallelAnnotationValue.asBoolean();
}

AnnotationValue restrict = annotation.value("restrictToAnnotatedClass");
if (restrict != null && restrict.asBoolean()) {
if (restrictToAnnotatedClass(annotation)) {
hasPerTestResources = true;
}

Expand Down Expand Up @@ -449,16 +449,6 @@ private Collection<AnnotationInstance> findQuarkusTestResourceInstances(Class<?>
annotation.target().asClass(), testClasses))))
.forEach(testResourceAnnotations::add);

// for (String listClassName : List.of(WithTestResource.List.class.getName(), QuarkusTestResource.List.class.getName())) {
// for (AnnotationInstance annotation : index.getAnnotations(DotName.createSimple(listClassName))) {
// for (AnnotationInstance nestedAnnotation : annotation.value().asNestedArray()) {
// // keep the list target
// if (keepTestResourceAnnotation(nestedAnnotation, annotation.target().asClass(), testClasses)) {
// testResourceAnnotations.add(nestedAnnotation);
// }
// }
// }
// }
return testResourceAnnotations;
}

Expand All @@ -472,13 +462,22 @@ private boolean keepTestResourceAnnotation(AnnotationInstance annotation, ClassI
// meta-annotations have already been handled in collectMetaAnnotations
return false;
}
AnnotationValue restrict = annotation.value("restrictToAnnotatedClass");
if (restrict != null && restrict.asBoolean()) {

if (restrictToAnnotatedClass(annotation)) {
return testClasses.contains(targetClass.name().toString('.'));
}

return true;
}

private boolean restrictToAnnotatedClass(AnnotationInstance annotation) {
AnnotationValue restrict = annotation.value("restrictToAnnotatedClass");

return (annotation.name().equals(WITH_TEST_RESOURCE) && ((restrict == null) || restrict.asBoolean()))
||
(annotation.name().equals(QUARKUS_TEST_RESOURCE) && ((restrict != null) && restrict.asBoolean()));
}

public static class TestResourceClassEntry {

private Class<? extends QuarkusTestResourceLifecycleManager> clazz;
Expand Down

0 comments on commit c8df67f

Please sign in to comment.