Search in sources :

Example 56 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.

@Test
public void imports_non_generic_method_return_type() {
    class NonGenericReturnType {
    }
    @SuppressWarnings("unused")
    class SomeClass {

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

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

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

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

Example 58 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_multiple_type_arguments.

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

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

Example 59 with JavaType

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

the class HasReturnTypeTest method function_get_raw_return_type.

@Test
public void function_get_raw_return_type() {
    abstract class TestClass implements Iterable<String> {
    }
    JavaType genericType = importClassWithContext(TestClass.class).getSuperclass().get();
    JavaClass expectedType = genericType.toErasure();
    assertThatType(GET_RAW_RETURN_TYPE.apply(newHasReturnType(genericType, expectedType))).as("result of GET_RAW_RETURN_TYPE").isEqualTo(expectedType);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test)

Example 60 with JavaType

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

the class HasReturnTypeTest method function_get_return_type.

@Test
public void function_get_return_type() {
    abstract class TestClass implements Iterable<String> {
    }
    JavaType expectedType = importClassWithContext(TestClass.class).getSuperclass().get();
    JavaClass rawType = expectedType.toErasure();
    assertThatType(GET_RETURN_TYPE.apply(newHasReturnType(expectedType, rawType))).as("result of GET_RETURN_TYPE").isEqualTo(expectedType);
}
Also used : JavaType(com.tngtech.archunit.core.domain.JavaType) JavaClass(com.tngtech.archunit.core.domain.JavaClass) 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