Search in sources :

Example 6 with JavaParameter

use of com.tngtech.archunit.core.domain.JavaParameter in project ArchUnit by TNG.

the class ClassFileImporterAnnotationsTest method imports_methods_with_multiple_parameters_with_annotations_but_unannotated_parameters_in_between.

@Test
public void imports_methods_with_multiple_parameters_with_annotations_but_unannotated_parameters_in_between() {
    JavaMethod method = new ClassFileImporter().importPackagesOf(ClassWithMethodWithAnnotatedParameters.class).get(ClassWithMethodWithAnnotatedParameters.class).getMethod(ClassWithMethodWithAnnotatedParameters.methodWithAnnotatedParametersGap, String.class, int.class, Object.class, List.class);
    List<Set<JavaAnnotation<JavaParameter>>> parameterAnnotations = method.getParameterAnnotations();
    assertThatAnnotations(parameterAnnotations.get(0)).isNotEmpty();
    assertThatAnnotations(parameterAnnotations.get(1)).isEmpty();
    assertThatAnnotations(parameterAnnotations.get(2)).isEmpty();
    assertThatAnnotations(parameterAnnotations.get(3)).isNotEmpty();
    List<JavaParameter> parameters = method.getParameters();
    for (int i = 0; i < 4; i++) {
        assertThat(parameterAnnotations.get(i)).isEqualTo(parameters.get(i).getAnnotations());
        assertThatAnnotations(parameterAnnotations.get(i)).match(ImmutableSet.copyOf(method.reflect().getParameterAnnotations()[i]));
    }
}
Also used : ClassWithMethodWithAnnotatedParameters(com.tngtech.archunit.core.importer.testexamples.annotatedparameters.ClassWithMethodWithAnnotatedParameters) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) JavaParameter(com.tngtech.archunit.core.domain.JavaParameter) Test(org.junit.Test)

Aggregations

JavaParameter (com.tngtech.archunit.core.domain.JavaParameter)6 Test (org.junit.Test)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)5 ClassWithMethodWithAnnotatedParameters (com.tngtech.archunit.core.importer.testexamples.annotatedparameters.ClassWithMethodWithAnnotatedParameters)5 Set (java.util.Set)5 JavaAnnotation (com.tngtech.archunit.core.domain.JavaAnnotation)2 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaConstructor (com.tngtech.archunit.core.domain.JavaConstructor)1 JavaEnumConstant (com.tngtech.archunit.core.domain.JavaEnumConstant)1 SimpleAnnotation (com.tngtech.archunit.core.importer.testexamples.annotatedclassimport.SimpleAnnotation)1 List (java.util.List)1