Search in sources :

Example 86 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_generic_field_type_of_inner_class.

@Test
public void creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_generic_field_type_of_inner_class() {
    @SuppressWarnings("unused")
    class OuterWithTypeParameter<OUTER extends String> {

        class SomeInner {

            class GenericFieldType<T> {
            }

            class SomeClass {

                GenericFieldType<OUTER> field;
            }
        }
    }
    JavaType genericFieldType = resetConfigurationAround(() -> {
        ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
        return importClassWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.SomeClass.class).getField("field").getType();
    });
    assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(typeVariable("OUTER").withoutUpperBounds());
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 87 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method references_type_variable_assigned_to_actual_type_argument_of_generic_field_type.

@Test
public void references_type_variable_assigned_to_actual_type_argument_of_generic_field_type() {
    @SuppressWarnings("unused")
    class GenericFieldType<T> {
    }
    @SuppressWarnings("unused")
    class SomeClass<OF_CLASS extends String> {

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

Example 88 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_parameterized_with_type_variable.

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

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

Example 89 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_type_arguments.

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

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

Example 90 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_wildcards_of_generic_field_type_bound_by_type_variables.

@Test
public void imports_wildcards_of_generic_field_type_bound_by_type_variables() {
    @SuppressWarnings("unused")
    class GenericFieldType<A, B> {
    }
    @SuppressWarnings("unused")
    class SomeClass<FIRST extends String, SECOND extends Serializable> {

        GenericFieldType<ClassParameterWithSingleTypeParameter<? extends FIRST>, ClassParameterWithSingleTypeParameter<? super SECOND>> field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("SECOND").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