Search in sources :

Example 61 with JavaType

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

Example 62 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_wildcards_of_generic_superclass_bound_by_type_variables.

@Test
public void imports_wildcards_of_generic_superclass_bound_by_type_variables() {
    @SuppressWarnings("unused")
    class BaseClass<A, B> {
    }
    class Child<FIRST extends String, SECOND extends Serializable> extends BaseClass<ClassParameterWithSingleTypeParameter<? extends FIRST>, ClassParameterWithSingleTypeParameter<? super SECOND>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("SECOND").withUpperBounds(Serializable.class)));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 63 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_concrete_array_bounds.

@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_concrete_array_bounds() {
    @SuppressWarnings("unused")
    class BaseClass<A, B, C> {
    }
    @SuppressWarnings("unused")
    class Child extends BaseClass<List<Serializable[]>, List<? extends Serializable[][]>, Map<? super String[], Map<Map<? super String[][][], ?>, Serializable[][]>>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).hasActualTypeArguments(parameterizedType(List.class).withTypeArguments(Serializable[].class), parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(Serializable[][].class), parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(String[].class), parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(String[][][].class), wildcardType()), concreteClass(Serializable[][].class))));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Serializable(java.io.Serializable) Map(java.util.Map) Test(org.junit.Test)

Example 64 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_multiple_type_arguments.

@Test
public void imports_generic_superclass_with_multiple_type_arguments() {
    @SuppressWarnings("unused")
    class BaseClass<A, B, C> {
    }
    @SuppressWarnings("unused")
    class Child extends BaseClass<String, Serializable, File> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).as("generic superclass").hasErasure(BaseClass.class).hasActualTypeArguments(String.class, Serializable.class, File.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 65 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_array_type_argument.

@Test
public void imports_generic_superclass_with_array_type_argument() {
    @SuppressWarnings("unused")
    class BaseClass<T> {
    }
    class Child extends BaseClass<String[]> {
    }
    JavaType genericSuperClass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperClass).as("generic superclass").hasErasure(BaseClass.class).hasActualTypeArguments(String[].class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Aggregations

JavaType (com.tngtech.archunit.core.domain.JavaType)133 Test (org.junit.Test)132 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)31 Serializable (java.io.Serializable)29 Map (java.util.Map)23 File (java.io.File)17 List (java.util.List)13 Reference (java.lang.ref.Reference)5 JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 JavaTypeVariable (com.tngtech.archunit.core.domain.JavaTypeVariable)3 JavaParameterizedType (com.tngtech.archunit.core.domain.JavaParameterizedType)1 SomeDeeplyNestedInterface (com.tngtech.archunit.core.importer.ClassFileImporterGenericInterfacesTest.Outer.SomeNestedInterface.SomeDeeplyNestedInterface)1 Path (java.nio.file.Path)1 Set (java.util.Set)1