Search in sources :

Example 31 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_complex_generic_field_type_with_multiple_nested_actual_type_arguments_with_concrete_array_bounds.

@Test
public void imports_complex_generic_field_type_with_multiple_nested_actual_type_arguments_with_concrete_array_bounds() {
    @SuppressWarnings("unused")
    class GenericFieldType<A, B, C> {
    }
    @SuppressWarnings("unused")
    class SomeClass {

        GenericFieldType<List<Serializable[]>, List<? extends Serializable[][]>, Map<? super String[], Map<Map<? super String[][][], ?>, Serializable[][]>>> field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).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 32 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_primitive_array_type_argument.

@Test
public void imports_generic_field_type_with_primitive_array_type_argument() {
    @SuppressWarnings("unused")
    class GenericFieldType<T> {
    }
    @SuppressWarnings("unused")
    class SomeClass {

        GenericFieldType<int[]> field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).as("generic field type").hasErasure(GenericFieldType.class).hasActualTypeArguments(int[].class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 33 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_actual_type_arguments_parameterized_with_bounded_wildcards.

@Test
public void imports_generic_field_type_with_actual_type_arguments_parameterized_with_bounded_wildcards() {
    @SuppressWarnings("unused")
    class GenericFieldType<A, B> {
    }
    @SuppressWarnings("unused")
    class SomeClass {

        GenericFieldType<ClassParameterWithSingleTypeParameter<? extends String>, ClassParameterWithSingleTypeParameter<? super File>> field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).as("generic field type").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 34 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_type_variable_as_generic_field_type.

@Test
public void imports_type_variable_as_generic_field_type() {
    @SuppressWarnings("unused")
    class SomeClass<T extends String> {

        T field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).as("generic field type").isInstanceOf(JavaTypeVariable.class).hasErasure(String.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) JavaTypeVariable(com.tngtech.archunit.core.domain.JavaTypeVariable) Test(org.junit.Test)

Example 35 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_multiple_actual_type_arguments_parameterized_with_concrete_classes.

@Test
public void imports_generic_field_type_with_multiple_actual_type_arguments_parameterized_with_concrete_classes() {
    @SuppressWarnings("unused")
    class GenericFieldType<A, B, C> {
    }
    @SuppressWarnings("unused")
    class SomeClass {

        GenericFieldType<ClassParameterWithSingleTypeParameter<File>, InterfaceParameterWithSingleTypeParameter<Serializable>, InterfaceParameterWithSingleTypeParameter<String>> field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).as("generic field type").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)

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