use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_complex_generic_code_unit_parameter_type_with_multiple_nested_actual_type_arguments_with_self_referencing_type_definitions.
@Test
@UseDataProvider
public void test_imports_complex_generic_code_unit_parameter_type_with_multiple_nested_actual_type_arguments_with_self_referencing_type_definitions(JavaCodeUnit codeUnit) {
JavaType genericParameterType = codeUnit.getParameterTypes().get(0);
// @formatter:off
assertThatType(genericParameterType).as("generic parameter type").hasActualTypeArguments(// assigned to ClassParameterWithThreeTypeParameters<A,_,_>
parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class)), // assigned to ClassParameterWithThreeTypeParameters<_,B,_>
parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.Entry.class).withTypeArguments(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class), parameterizedType(Map.Entry.class).withTypeArguments(concreteClass(String.class), typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class))), parameterizedType(Map.class).withTypeArguments(wildcardType().withUpperBound(String.class), parameterizedType(Map.class).withTypeArguments(wildcardType().withUpperBound(Serializable.class), parameterizedType(List.class).withTypeArguments(parameterizedType(List.class).withTypeArguments(wildcardType().withUpperBound(parameterizedType(Set.class).withTypeArguments(wildcardType().withLowerBound(parameterizedType(Iterable.class).withTypeArguments(wildcardType().withLowerBound(parameterizedType(Map.class).withTypeArguments(typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class), wildcardType()))))))))))), // assigned to ClassParameterWithThreeTypeParameters<_,_,C>
parameterizedType(Comparable.class).withTypeArguments(parameterizedType(codeUnit.getOwner().reflect()).withTypeArguments(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class), typeVariable("SECOND").withUpperBounds(Serializable.class, Cloneable.class))));
// @formatter:on
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericCodeUnitParameterTypesTest method test_imports_raw_generic_code_unit_parameter_type_as_JavaClass_instead_of_JavaParameterizedType.
@Test
@UseDataProvider
public void test_imports_raw_generic_code_unit_parameter_type_as_JavaClass_instead_of_JavaParameterizedType(JavaCodeUnit codeUnit) {
JavaType rawGenericParameterType = codeUnit.getParameterTypes().get(0);
assertThatType(rawGenericParameterType).as("raw generic parameter type").matches(ClassParameterWithSingleTypeParameter.class);
}
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_unbound_wildcard.
@Test
public void imports_generic_field_type_with_single_actual_type_argument_parameterized_with_unbound_wildcard() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<ClassParameterWithSingleTypeParameter<?>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameter());
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_one_type_argument.
@Test
public void imports_generic_field_type_with_one_type_argument() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<String> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasErasure(GenericFieldType.class).hasActualTypeArguments(String.class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds.
@Test
public void imports_generic_field_type_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds() {
@SuppressWarnings("unused")
class GenericFieldType<A, B> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<ClassParameterWithSingleTypeParameter<Map<? extends Serializable, ? super File>>, ClassParameterWithSingleTypeParameter<Reference<? super String>>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field 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)));
}
Aggregations