Search in sources :

Example 26 with JavaType

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

the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_complex_generic_code_unit_parameter_type_with_multiple_nested_actual_type_arguments_with_self_referencing_type_definitions.

@Test
@UseDataProvider
public void test_imports_complex_generic_code_unit_parameter_type_with_multiple_nested_actual_type_arguments_with_self_referencing_type_definitions(JavaCodeUnit codeUnit) {
    JavaType genericParameterType = codeUnit.getParameterTypes().get(0);
    // @formatter:off
    assertThatType(genericParameterType).as("generic parameter type").hasActualTypeArguments(// assigned to ClassParameterWithThreeTypeParameters<A,_,_>
    parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class)), // assigned to ClassParameterWithThreeTypeParameters<_,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 ClassParameterWithThreeTypeParameters<_,_,C>
    parameterizedType(Comparable.class).withTypeArguments(parameterizedType(codeUnit.getOwner().reflect()).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 27 with JavaType

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

the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_raw_generic_code_unit_parameter_type_as_JavaClass_instead_of_JavaParameterizedType.

@Test
@UseDataProvider
public void test_imports_raw_generic_code_unit_parameter_type_as_JavaClass_instead_of_JavaParameterizedType(JavaCodeUnit codeUnit) {
    JavaType rawGenericParameterType = codeUnit.getParameterTypes().get(0);
    assertThatType(rawGenericParameterType).as("raw generic parameter type").matches(ClassParameterWithSingleTypeParameter.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 28 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_single_actual_type_argument_parameterized_with_unbound_wildcard.

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

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

Example 29 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_one_type_argument.

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

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

Example 30 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_with_multiple_wildcards_with_various_bounds.

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

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

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