Search in sources :

Example 41 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method test_imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_interface_with_self_referencing_type_definitions.

@Test
@UseDataProvider
public void test_imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_interface_with_self_referencing_type_definitions(Class<?> testInput) {
    JavaType genericInterface = getOnlyElement(importClassWithOnlyGenericTypeResolution(testInput).getInterfaces());
    // @formatter:off
    assertThatType(genericInterface).as("generic interface").hasActualTypeArguments(// assigned to InterfaceWithThreeTypeParameters<A,_,_>
    parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class)), // assigned to InterfaceWithThreeTypeParameters<_,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 InterfaceWithThreeTypeParameters<_,_,C>
    parameterizedType(Comparable.class).withTypeArguments(parameterizedType(testInput).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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 42 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method imports_nested_generic_interfaces.

@Test
public void imports_nested_generic_interfaces() {
    @SuppressWarnings("unused")
    class Child<T> implements SomeDeeplyNestedInterface<File, SomeNestedInterface<Path, Path>> {
    }
    JavaType genericInterface = getOnlyElement(importClassWithOnlyGenericTypeResolution(Child.class).getInterfaces());
    assertThatType(genericInterface).as("generic interface").hasErasure(SomeDeeplyNestedInterface.class).hasActualTypeArguments(concreteClass(File.class), parameterizedType(SomeNestedInterface.class).withTypeArguments(Path.class, Path.class));
}
Also used : Path(java.nio.file.Path) JavaType(com.tngtech.archunit.core.domain.JavaType) SomeDeeplyNestedInterface(com.tngtech.archunit.core.importer.ClassFileImporterGenericInterfacesTest.Outer.SomeNestedInterface.SomeDeeplyNestedInterface) File(java.io.File) Test(org.junit.Test)

Example 43 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method test_imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_interface_with_generic_array_bounds.

@Test
@UseDataProvider
public void test_imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_interface_with_generic_array_bounds(Class<?> testInput) {
    JavaType genericInterface = getOnlyElement(importClassWithOnlyGenericTypeResolution(testInput).getInterfaces());
    assertThatType(genericInterface).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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 44 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method test_imports_type_of_generic_interface_with_parameterized_array_bounds.

@Test
@UseDataProvider
public void test_imports_type_of_generic_interface_with_parameterized_array_bounds(Class<?> testInput) {
    JavaType genericInterface = getOnlyElement(importClassWithOnlyGenericTypeResolution(testInput).getInterfaces());
    assertThatType(genericInterface).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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 45 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method imports_wildcards_of_generic_interface_bound_by_type_variables_of_enclosing_classes.

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

        class SomeInner {

            class Child implements InterfaceWithTwoTypeParameters<ClassParameterWithSingleTypeParameter<? extends OUTER_ONE>, ClassParameterWithSingleTypeParameter<? super OUTER_TWO>> {
            }
        }
    }
    JavaType genericInterface = getOnlyElement(importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.Child.class, OuterWithTypeParameter.SomeInner.class, OuterWithTypeParameter.class).get(OuterWithTypeParameter.SomeInner.Child.class).getInterfaces());
    assertThatType(genericInterface).as("generic interface").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)

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