Search in sources :

Example 46 with JavaType

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

the class ClassFileImporterGenericInterfacesTest method imports_generic_interface_with_multiple_actual_type_arguments_parameterized_with_concrete_classes.

@Test
public void imports_generic_interface_with_multiple_actual_type_arguments_parameterized_with_concrete_classes() {
    class Child implements InterfaceWithThreeTypeParameters<ClassParameterWithSingleTypeParameter<File>, InterfaceWithOneTypeParameter<Serializable>, InterfaceWithOneTypeParameter<String>> {
    }
    JavaType genericInterface = getOnlyElement(importClassWithOnlyGenericTypeResolution(Child.class).getInterfaces());
    assertThatType(genericInterface).as("generic interface").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(File.class), parameterizedType(InterfaceWithOneTypeParameter.class).withTypeArguments(Serializable.class), parameterizedType(InterfaceWithOneTypeParameter.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)

Example 47 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_generic_method_return_type_with_single_unbound_wildcard.

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

        GenericReturnType<?> method() {
            return null;
        }
    }
    JavaType genericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericReturnType).as("generic return type").hasActualTypeArguments(wildcardType());
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 48 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_complex_generic_array_method_return_type.

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

        GenericReturnType<Map<? super String, Map<Map<? super String, ?>, Serializable>>>[] method() {
            return null;
        }
    }
    JavaType genericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericReturnType).matches(genericArray(GenericReturnType.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", " + Map.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", ?>, " + Serializable.class.getName() + ">>>[]").withComponentType(parameterizedType(GenericReturnType.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) Map(java.util.Map) Test(org.junit.Test)

Example 49 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_generic_method_return_type_with_actual_type_arguments_parameterized_with_bounded_wildcards.

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

        GenericReturnType<ClassParameterWithSingleTypeParameter<? extends String>, ClassParameterWithSingleTypeParameter<? super File>> method() {
            return null;
        }
    }
    JavaType genericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericReturnType).as("generic return 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 50 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_generic_method_return_type_with_primitive_array_type_argument.

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

        GenericReturnType<int[]> method() {
            return null;
        }
    }
    JavaType genericMethodReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericMethodReturnType).as("generic method return type").hasErasure(GenericReturnType.class).hasActualTypeArguments(int[].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