Search in sources :

Example 1 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_one_type_argument.

@Test
public void imports_generic_superclass_with_one_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)

Example 2 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_multiple_actual_type_arguments_parameterized_with_concrete_classes.

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

Example 3 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_self_referencing_type_definitions.

@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_self_referencing_type_definitions() {
    @SuppressWarnings("unused")
    class BaseClass<A, B, C> {
    }
    class Child<FIRST extends String & Serializable, SECOND extends Serializable & Cloneable> extends BaseClass<// assigned to BaseClass<A,_,_>
    List<? extends FIRST>, // assigned to BaseClass<_,B,_>
    Map<Map.Entry<FIRST, Map.Entry<String, SECOND>>, Map<? extends String, Map<? extends Serializable, List<List<? extends Set<? super Iterable<? super Map<SECOND, ?>>>>>>>>, // assigned to BaseClass<_,_,C>
    Comparable<Child<FIRST, SECOND>>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    // @formatter:off
    assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(// assigned to BaseClass<A,_,_>
    parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class)), // assigned to BaseClass<_,B,_>
    parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.Entry.class).withTypeArguments(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class), parameterizedType(Map.Entry.class).withTypeArguments(concreteClass(String.class), typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class))), parameterizedType(Map.class).withTypeArguments(wildcardType().withUpperBound(String.class), parameterizedType(Map.class).withTypeArguments(wildcardType().withUpperBound(Serializable.class), parameterizedType(List.class).withTypeArguments(parameterizedType(List.class).withTypeArguments(wildcardType().withUpperBound(parameterizedType(Set.class).withTypeArguments(wildcardType().withLowerBound(parameterizedType(Iterable.class).withTypeArguments(wildcardType().withLowerBound(parameterizedType(Map.class).withTypeArguments(typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class), wildcardType()))))))))))), // assigned to BaseClass<_,_,C>
    parameterizedType(Comparable.class).withTypeArguments(parameterizedType(Child.class).withTypeArguments(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class), typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class))));
// @formatter:on
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Serializable(java.io.Serializable) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 4 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_type_of_generic_superclass_with_parameterized_array_bounds.

@Test
public void imports_type_of_generic_superclass_with_parameterized_array_bounds() {
    @SuppressWarnings("unused")
    class BaseClass<A, B, C> {
    }
    class Child extends BaseClass<List<String>[], List<String[]>[][], List<String[][]>[][][]> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).hasActualTypeArguments(genericArray(parameterizedTypeArrayName(List.class, String.class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String.class)), genericArray(parameterizedTypeArrayName(List.class, String[].class, 2)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[].class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String[].class))), genericArray(parameterizedTypeArrayName(List.class, String[][].class, 3)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[][].class, 2)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[][].class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String[][].class)))));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) List(java.util.List) Test(org.junit.Test)

Example 5 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method references_outer_type_variable_assigned_to_actual_type_argument_of_generic_superclass_of_inner_class.

@Test
public void references_outer_type_variable_assigned_to_actual_type_argument_of_generic_superclass_of_inner_class() {
    @SuppressWarnings("unused")
    class OuterWithTypeParameter<OUTER extends String> {

        class SomeInner {

            @SuppressWarnings("unused")
            class BaseClass<T> {
            }

            class Child extends BaseClass<OUTER> {
            }
        }
    }
    JavaType genericSuperclass = importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.Child.class, OuterWithTypeParameter.SomeInner.class, OuterWithTypeParameter.class).get(OuterWithTypeParameter.SomeInner.Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(typeVariable("OUTER").withUpperBounds(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