Search in sources :

Example 51 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_non_generic_method_return_type_on_generic_signature.

@Test
public void imports_non_generic_method_return_type_on_generic_signature() {
    @SuppressWarnings("unused")
    class SomeClass {

        <T> Object method(T irrelevant) {
            return null;
        }

        <T> int primitive(T irrelevant) {
            return 0;
        }
    }
    JavaClass javaClass = importClassWithOnlyGenericTypeResolution(SomeClass.class);
    JavaType returnType = javaClass.getMethod("method", Object.class).getReturnType();
    assertThatType(returnType).as("return type").matches(Object.class);
    returnType = javaClass.getMethod("primitive", Object.class).getReturnType();
    assertThatType(returnType).as("return type").matches(int.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test)

Example 52 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_raw_generic_method_return_type_as_JavaClass_instead_of_JavaParameterizedType.

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

        GenericReturnType method() {
            return null;
        }
    }
    JavaType rawGenericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(rawGenericReturnType).as("raw generic method return type").matches(GenericReturnType.class);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) Test(org.junit.Test)

Example 53 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_complex_generic_method_return_type_with_multiple_nested_actual_type_arguments_with_concrete_array_bounds.

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

        GenericReturnType<List<Serializable[]>, List<? extends Serializable[][]>, Map<? super String[], Map<Map<? super String[][][], ?>, Serializable[][]>>> method() {
            return null;
        }
    }
    JavaType genericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericReturnType).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 : Serializable(java.io.Serializable) JavaType(com.tngtech.archunit.core.domain.JavaType) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 54 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method imports_generic_method_return_type_parameterized_with_type_variable.

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

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

Example 55 with JavaType

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

the class ClassFileImporterGenericMethodReturnTypesTest method references_type_variable_assigned_to_actual_type_argument_of_generic_method_return_type.

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

        GenericReturnType<ClassParameterWithSingleTypeParameter<OF_CLASS>> method() {
            return null;
        }
    }
    JavaType genericReturnType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getMethod("method").getReturnType();
    assertThatType(genericReturnType).as("generic return 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)

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