Search in sources :

Example 96 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_wildcards_bound_by_type_variables_of_enclosing_classes_that_are_out_of_context.

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

        class SomeInner {

            @SuppressWarnings("unused")
            class GenericFieldType<A, B> {
            }

            class SomeClass {

                GenericFieldType<ClassParameterWithSingleTypeParameter<? extends OUTER_ONE>, ClassParameterWithSingleTypeParameter<? super OUTER_TWO>> field;
            }
        }
    }
    JavaType genericFieldType = resetConfigurationAround(() -> {
        ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
        return importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.SomeClass.class, ClassParameterWithSingleTypeParameter.class).get(OuterWithTypeParameter.SomeInner.SomeClass.class).getField("field").getType();
    });
    assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("OUTER_ONE").withoutUpperBounds()), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("OUTER_TWO").withoutUpperBounds()));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 97 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_argument_parameterized_with_type_variable.

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

        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")));
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 98 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_concrete_class.

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

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

Example 99 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_complex_generic_array_field_type.

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

        GenericFieldType<Map<? super String, Map<Map<? super String, ?>, Serializable>>>[] field;
    }
    JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(genericFieldType).matches(genericArray(GenericFieldType.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", " + Map.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", ?>, " + Serializable.class.getName() + ">>>[]").withComponentType(parameterizedType(GenericFieldType.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 : Serializable(java.io.Serializable) JavaType(com.tngtech.archunit.core.domain.JavaType) Map(java.util.Map) Test(org.junit.Test)

Example 100 with JavaType

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

the class ClassFileImporterGenericFieldTypesTest method imports_non_generic_field_type.

@Test
public void imports_non_generic_field_type() {
    class NonGenericFieldType {
    }
    @SuppressWarnings("unused")
    class SomeClass {

        NonGenericFieldType field;
    }
    JavaType fieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
    assertThatType(fieldType).as("generic field type").matches(NonGenericFieldType.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