use of io.micronaut.inject.qualifiers.Qualifiers in project micronaut-test by micronaut-projects.
the class MicronautJunit5Extension method resolveQualifier.
/**
* Build a qualifier for the given argument.
* @param argument The argument
* @param <T> The type
* @return The resolved qualifier
*/
@SuppressWarnings("unchecked")
private static <T> Qualifier<T> resolveQualifier(Argument<?> argument) {
AnnotationMetadata annotationMetadata = Objects.requireNonNull(argument, "Argument cannot be null").getAnnotationMetadata();
boolean hasMetadata = annotationMetadata != AnnotationMetadata.EMPTY_METADATA;
List<String> qualifierTypes = hasMetadata ? annotationMetadata.getAnnotationNamesByStereotype(AnnotationUtil.QUALIFIER) : null;
if (CollectionUtils.isNotEmpty(qualifierTypes)) {
if (qualifierTypes.size() == 1) {
return Qualifiers.byAnnotation(annotationMetadata, qualifierTypes.iterator().next());
} else {
final Qualifier[] qualifiers = qualifierTypes.stream().map((type) -> Qualifiers.byAnnotation(annotationMetadata, type)).toArray(Qualifier[]::new);
return Qualifiers.<T>byQualifiers(qualifiers);
}
}
return null;
}
Aggregations