Search in sources :

Example 1 with Qualifiers

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;
}
Also used : java.util(java.util) InterceptedProxy(io.micronaut.aop.InterceptedProxy) TestContext(io.micronaut.test.context.TestContext) Qualifier(io.micronaut.context.Qualifier) Nested(org.junit.jupiter.api.Nested) Constructor(java.lang.reflect.Constructor) ExecutableMethod(io.micronaut.inject.ExecutableMethod) ApplicationContext(io.micronaut.context.ApplicationContext) MockBean(io.micronaut.test.annotation.MockBean) TestInstance(org.junit.jupiter.api.TestInstance) Executable(java.lang.reflect.Executable) Argument(io.micronaut.core.type.Argument) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Method(java.lang.reflect.Method) Property(io.micronaut.context.annotation.Property) Qualifiers(io.micronaut.inject.qualifiers.Qualifiers) Value(io.micronaut.context.annotation.Value) Field(java.lang.reflect.Field) FieldInjectionPoint(io.micronaut.inject.FieldInjectionPoint) AnnotationSupport(org.junit.platform.commons.support.AnnotationSupport) MicronautTestValue(io.micronaut.test.annotation.MicronautTestValue) AnnotationUtil(io.micronaut.core.annotation.AnnotationUtil) CollectionUtils(io.micronaut.core.util.CollectionUtils) AbstractMicronautExtension(io.micronaut.test.extensions.AbstractMicronautExtension) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) BeanDefinition(io.micronaut.inject.BeanDefinition) org.junit.jupiter.api.extension(org.junit.jupiter.api.extension) TestPropertyProvider(io.micronaut.test.support.TestPropertyProvider) AnnotatedElement(java.lang.reflect.AnnotatedElement) Qualifier(io.micronaut.context.Qualifier) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata)

Aggregations

InterceptedProxy (io.micronaut.aop.InterceptedProxy)1 ApplicationContext (io.micronaut.context.ApplicationContext)1 Qualifier (io.micronaut.context.Qualifier)1 Property (io.micronaut.context.annotation.Property)1 Value (io.micronaut.context.annotation.Value)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 AnnotationUtil (io.micronaut.core.annotation.AnnotationUtil)1 Argument (io.micronaut.core.type.Argument)1 CollectionUtils (io.micronaut.core.util.CollectionUtils)1 BeanDefinition (io.micronaut.inject.BeanDefinition)1 ExecutableMethod (io.micronaut.inject.ExecutableMethod)1 FieldInjectionPoint (io.micronaut.inject.FieldInjectionPoint)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 MicronautTestValue (io.micronaut.test.annotation.MicronautTestValue)1 MockBean (io.micronaut.test.annotation.MockBean)1 TestContext (io.micronaut.test.context.TestContext)1 AbstractMicronautExtension (io.micronaut.test.extensions.AbstractMicronautExtension)1 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)1 TestPropertyProvider (io.micronaut.test.support.TestPropertyProvider)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1