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);
}
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);
}
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))));
}
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"));
}
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)));
}
Aggregations