Search in sources :

Example 1 with JavaWildcardType

use of com.tngtech.archunit.core.domain.JavaWildcardType 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 JavaWildcardType

use of com.tngtech.archunit.core.domain.JavaWildcardType 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)

Aggregations

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