Search in sources :

Example 66 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_of_enclosing_classes.

@Test
public void imports_wildcards_of_generic_superclass_bound_by_type_variables_of_enclosing_classes() {
    @SuppressWarnings("unused")
    class OuterWithTypeParameter<OUTER_ONE extends String, OUTER_TWO extends Serializable> {

        class SomeInner {

            @SuppressWarnings("unused")
            class BaseClass<A, B> {
            }

            class Child extends BaseClass<ClassParameterWithSingleTypeParameter<? extends OUTER_ONE>, ClassParameterWithSingleTypeParameter<? super OUTER_TWO>> {
            }
        }
    }
    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(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("OUTER_ONE").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("OUTER_TWO").withUpperBounds(Serializable.class)));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 67 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds.

@Test
public void imports_generic_superclass_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds() {
    @SuppressWarnings("unused")
    class BaseClass<A, B> {
    }
    class Child extends BaseClass<ClassParameterWithSingleTypeParameter<Map<? extends Serializable, ? super File>>, ClassParameterWithSingleTypeParameter<Reference<? super String>>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(parameterizedType(Map.class).withWildcardTypeParameters(wildcardType().withUpperBound(Serializable.class), wildcardType().withLowerBound(File.class))), parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(parameterizedType(Reference.class).withWildcardTypeParameterWithLowerBound(String.class)));
}
Also used : Serializable(java.io.Serializable) JavaType(com.tngtech.archunit.core.domain.JavaType) Reference(java.lang.ref.Reference) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 68 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method references_type_variable_assigned_to_actual_type_argument_of_generic_superclass.

@Test
public void references_type_variable_assigned_to_actual_type_argument_of_generic_superclass() {
    @SuppressWarnings("unused")
    class BaseClass<SUPER> {
    }
    class Child<SUB extends String> extends BaseClass<ClassParameterWithSingleTypeParameter<SUB>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(typeVariable("SUB").withUpperBounds(String.class)));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 69 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_raw_generic_superclass_as_JavaClass_instead_of_JavaParameterizedType.

@Test
public void imports_raw_generic_superclass_as_JavaClass_instead_of_JavaParameterizedType() {
    @SuppressWarnings("unused")
    class BaseClass<T> {
    }
    @SuppressWarnings("rawtypes")
    class Child extends BaseClass {
    }
    JavaType rawGenericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(rawGenericSuperclass).as("raw generic superclass").matches(BaseClass.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 70 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_generic_array_bounds.

@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_generic_array_bounds() {
    @SuppressWarnings("unused")
    class BaseClass<A, B, C> {
    }
    @SuppressWarnings("unused")
    class Child<X extends Serializable, Y extends String> extends BaseClass<List<X[]>, List<? extends X[][]>, Map<? super Y[], Map<Map<? super Y[][][], ?>, X[][]>>> {
    }
    JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
    assertThatType(genericSuperclass).hasActualTypeArguments(parameterizedType(List.class).withTypeArguments(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class))), parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(genericArray(typeVariableArrayName("X", 2)).withComponentType(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class)))), parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(genericArray(typeVariableArrayName("Y", 1)).withComponentType(typeVariable("Y").withUpperBounds(String.class))), parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(genericArray(typeVariableArrayName("Y", 3)).withComponentType(genericArray(typeVariableArrayName("Y", 2)).withComponentType(genericArray(typeVariableArrayName("Y", 1)).withComponentType(typeVariable("Y").withUpperBounds(String.class))))), wildcardType()), genericArray(typeVariableArrayName("X", 2)).withComponentType(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class))))));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Serializable(java.io.Serializable) Map(java.util.Map) 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