Search in sources :

Example 11 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_parameterized_with_bounded_wildcards.

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

Example 12 with JavaType

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

the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_primitive_array_type_argument.

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

Example 13 with JavaType

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

the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_complex_generic_array_code_unit_parameter_type.

@Test
@UseDataProvider
public void test_imports_complex_generic_array_code_unit_parameter_type(JavaCodeUnit codeUnit) {
    JavaType genericParameterType = codeUnit.getParameterTypes().get(0);
    assertThatType(genericParameterType).matches(genericArray(List.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", " + Map.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", ?>, " + Serializable.class.getName() + ">>>[]").withComponentType(parameterizedType(List.class).withTypeArguments(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) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 14 with JavaType

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

the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_generic_code_unit_parameter_type_with_multiple_type_arguments.

@Test
@UseDataProvider
public void test_imports_generic_code_unit_parameter_type_with_multiple_type_arguments(JavaCodeUnit codeUnit) {
    JavaType genericParameterType = codeUnit.getParameterTypes().get(0);
    assertThatType(genericParameterType).as("generic parameter type").hasErasure(ClassParameterWithThreeTypeParameters.class).hasActualTypeArguments(String.class, Serializable.class, File.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with JavaType

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

the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_references_type_variable_assigned_to_actual_type_argument_of_generic_code_unit_parameter_type.

@Test
@UseDataProvider
public void test_references_type_variable_assigned_to_actual_type_argument_of_generic_code_unit_parameter_type(JavaCodeUnit codeUnit) {
    JavaType genericParameterType = codeUnit.getParameterTypes().get(0);
    assertThatType(genericParameterType).as("generic parameter type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(typeVariable("OF_CLASS").withUpperBounds(String.class)));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

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