Search in sources :

Example 1 with JavaParameterizedType

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

the class ClassFileImporterAutomaticResolutionTest method test_automatically_resolves_parameterized_generic_type_bounds.

@Test
@UseDataProvider
public void test_automatically_resolves_parameterized_generic_type_bounds(JavaParameterizedType actual1stLevel, Class<?> expected1stLevel, Class<?> expected2ndLevel, Class<?> expected3rdLevel) {
    assertThat(actual1stLevel.toErasure()).isFullyImported(true);
    assertThatType(actual1stLevel.toErasure()).matches(expected1stLevel);
    JavaParameterizedType actual2ndLevel = (JavaParameterizedType) getOnlyElement(((JavaWildcardType) getOnlyElement(actual1stLevel.getActualTypeArguments())).getUpperBounds());
    assertThat(actual2ndLevel.toErasure()).isFullyImported(true);
    assertThatType(actual2ndLevel.toErasure()).matches(expected2ndLevel);
    JavaClass actual3rdLevel = (JavaClass) getOnlyElement(((JavaWildcardType) actual2ndLevel.getActualTypeArguments().get(1)).getLowerBounds());
    assertThat(actual3rdLevel.toErasure()).isFullyImported(true);
    assertThatType(actual3rdLevel.toErasure()).matches(expected3rdLevel);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaWildcardType(com.tngtech.archunit.core.domain.JavaWildcardType) JavaParameterizedType(com.tngtech.archunit.core.domain.JavaParameterizedType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with JavaParameterizedType

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

the class ClassFileImporterAutomaticResolutionTest method getFirstTypeArgumentUpperBound.

private static JavaType getFirstTypeArgumentUpperBound(JavaType type) {
    JavaParameterizedType parameterizedType = (JavaParameterizedType) type;
    JavaWildcardType firstTypeArgument = (JavaWildcardType) parameterizedType.getActualTypeArguments().get(0);
    return firstTypeArgument.getUpperBounds().get(0);
}
Also used : JavaWildcardType(com.tngtech.archunit.core.domain.JavaWildcardType) JavaParameterizedType(com.tngtech.archunit.core.domain.JavaParameterizedType)

Example 3 with JavaParameterizedType

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

the class JavaTypeAssertion method hasActualTypeArguments.

public void hasActualTypeArguments(ExpectedConcreteType... typeArguments) {
    assertThat(actual).isInstanceOf(JavaParameterizedType.class);
    JavaParameterizedType parameterizedType = (JavaParameterizedType) this.actual;
    List<JavaType> actualTypeArguments = parameterizedType.getActualTypeArguments();
    DescriptionContext context = new DescriptionContext(actual.getName()).describeTypeParameters().step("actual type arguments");
    assertThat(actualTypeArguments).as(context.toString()).hasSameSizeAs(typeArguments);
    for (int i = 0; i < actualTypeArguments.size(); i++) {
        typeArguments[i].assertMatchWith(actualTypeArguments.get(i), context.describeElement(i, actualTypeArguments.size()));
    }
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) JavaParameterizedType(com.tngtech.archunit.core.domain.JavaParameterizedType)

Aggregations

JavaParameterizedType (com.tngtech.archunit.core.domain.JavaParameterizedType)3 JavaWildcardType (com.tngtech.archunit.core.domain.JavaWildcardType)2 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaType (com.tngtech.archunit.core.domain.JavaType)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Test (org.junit.Test)1