use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_wildcards_of_generic_superclass_bound_by_type_variables_of_enclosing_classes.
@Test
public void imports_wildcards_of_generic_superclass_bound_by_type_variables_of_enclosing_classes() {
@SuppressWarnings("unused")
class OuterWithTypeParameter<OUTER_ONE extends String, OUTER_TWO extends Serializable> {
class SomeInner {
@SuppressWarnings("unused")
class BaseClass<A, B> {
}
class Child extends BaseClass<ClassParameterWithSingleTypeParameter<? extends OUTER_ONE>, ClassParameterWithSingleTypeParameter<? super OUTER_TWO>> {
}
}
}
JavaType genericSuperclass = importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.Child.class, OuterWithTypeParameter.SomeInner.class, OuterWithTypeParameter.class).get(OuterWithTypeParameter.SomeInner.Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("OUTER_ONE").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("OUTER_TWO").withUpperBounds(Serializable.class)));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds.
@Test
public void imports_generic_superclass_with_actual_type_arguments_with_multiple_wildcards_with_various_bounds() {
@SuppressWarnings("unused")
class BaseClass<A, B> {
}
class Child extends BaseClass<ClassParameterWithSingleTypeParameter<Map<? extends Serializable, ? super File>>, ClassParameterWithSingleTypeParameter<Reference<? super String>>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").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)));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method references_type_variable_assigned_to_actual_type_argument_of_generic_superclass.
@Test
public void references_type_variable_assigned_to_actual_type_argument_of_generic_superclass() {
@SuppressWarnings("unused")
class BaseClass<SUPER> {
}
class Child<SUB extends String> extends BaseClass<ClassParameterWithSingleTypeParameter<SUB>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(typeVariable("SUB").withUpperBounds(String.class)));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_raw_generic_superclass_as_JavaClass_instead_of_JavaParameterizedType.
@Test
public void imports_raw_generic_superclass_as_JavaClass_instead_of_JavaParameterizedType() {
@SuppressWarnings("unused")
class BaseClass<T> {
}
@SuppressWarnings("rawtypes")
class Child extends BaseClass {
}
JavaType rawGenericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(rawGenericSuperclass).as("raw generic superclass").matches(BaseClass.class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_generic_array_bounds.
@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_generic_array_bounds() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
@SuppressWarnings("unused")
class Child<X extends Serializable, Y extends String> extends BaseClass<List<X[]>, List<? extends X[][]>, Map<? super Y[], Map<Map<? super Y[][][], ?>, X[][]>>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).hasActualTypeArguments(parameterizedType(List.class).withTypeArguments(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class))), parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(genericArray(typeVariableArrayName("X", 2)).withComponentType(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class)))), parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(genericArray(typeVariableArrayName("Y", 1)).withComponentType(typeVariable("Y").withUpperBounds(String.class))), parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(genericArray(typeVariableArrayName("Y", 3)).withComponentType(genericArray(typeVariableArrayName("Y", 2)).withComponentType(genericArray(typeVariableArrayName("Y", 1)).withComponentType(typeVariable("Y").withUpperBounds(String.class))))), wildcardType()), genericArray(typeVariableArrayName("X", 2)).withComponentType(genericArray(typeVariableArrayName("X", 1)).withComponentType(typeVariable("X").withUpperBounds(Serializable.class))))));
}
Aggregations