Search in sources :

Example 1 with SimpleAnnotation

use of com.tngtech.archunit.core.importer.testexamples.annotatedclassimport.SimpleAnnotation in project ArchUnit by TNG.

the class ClassFileImporterAnnotationsTest method imports_parameter_annotations_correctly_for_synthetic_constructor_parameter.

@Test
public void imports_parameter_annotations_correctly_for_synthetic_constructor_parameter() {
    @SuppressWarnings("unused")
    class LocalClassThusSyntheticFirstConstructorParameter {

        LocalClassThusSyntheticFirstConstructorParameter(Object notAnnotated, @SimpleAnnotation("test") List<String> annotated) {
        }
    }
    JavaConstructor constructor = getOnlyElement(new ClassFileImporter().importClasses(LocalClassThusSyntheticFirstConstructorParameter.class, String.class).get(LocalClassThusSyntheticFirstConstructorParameter.class).getConstructors());
    List<Set<JavaAnnotation<JavaParameter>>> parameterAnnotations = constructor.getParameterAnnotations();
    assertThat(parameterAnnotations).as("parameter annotations").hasSize(2);
    assertThatAnnotations(parameterAnnotations.get(0)).isEmpty();
    assertThatAnnotations(parameterAnnotations.get(1)).isNotEmpty();
    List<JavaParameter> parameters = constructor.getParameters();
    for (int i = 0; i < parameterAnnotations.size(); i++) {
        assertThat(parameterAnnotations.get(i)).isEqualTo(parameters.get(i).getAnnotations());
        assertThatAnnotations(parameterAnnotations.get(i)).match(ImmutableSet.copyOf(constructor.reflect().getParameterAnnotations()[i]));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SimpleAnnotation(com.tngtech.archunit.core.importer.testexamples.annotatedclassimport.SimpleAnnotation) JavaParameter(com.tngtech.archunit.core.domain.JavaParameter) List(java.util.List) JavaConstructor(com.tngtech.archunit.core.domain.JavaConstructor) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 JavaConstructor (com.tngtech.archunit.core.domain.JavaConstructor)1 JavaParameter (com.tngtech.archunit.core.domain.JavaParameter)1 SimpleAnnotation (com.tngtech.archunit.core.importer.testexamples.annotatedclassimport.SimpleAnnotation)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.junit.Test)1