use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_one_type_argument.
@Test
public void imports_generic_superclass_with_one_type_argument() {
@SuppressWarnings("unused")
class BaseClass<T> {
}
class Child extends BaseClass<String> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasErasure(BaseClass.class).hasActualTypeArguments(String.class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_multiple_actual_type_arguments_parameterized_with_concrete_classes.
@Test
public void imports_generic_superclass_with_multiple_actual_type_arguments_parameterized_with_concrete_classes() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
class Child extends BaseClass<ClassParameterWithSingleTypeParameter<File>, InterfaceParameterWithSingleTypeParameter<Serializable>, InterfaceParameterWithSingleTypeParameter<String>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(File.class), parameterizedType(InterfaceParameterWithSingleTypeParameter.class).withTypeArguments(Serializable.class), parameterizedType(InterfaceParameterWithSingleTypeParameter.class).withTypeArguments(String.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_self_referencing_type_definitions.
@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_self_referencing_type_definitions() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
class Child<FIRST extends String & Serializable, SECOND extends Serializable & Cloneable> extends BaseClass<// assigned to BaseClass<A,_,_>
List<? extends FIRST>, // assigned to BaseClass<_,B,_>
Map<Map.Entry<FIRST, Map.Entry<String, SECOND>>, Map<? extends String, Map<? extends Serializable, List<List<? extends Set<? super Iterable<? super Map<SECOND, ?>>>>>>>>, // assigned to BaseClass<_,_,C>
Comparable<Child<FIRST, SECOND>>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
// @formatter:off
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(// assigned to BaseClass<A,_,_>
parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class, Serializable.class)), // assigned to BaseClass<_,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 BaseClass<_,_,C>
parameterizedType(Comparable.class).withTypeArguments(parameterizedType(Child.class).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 ClassFileImporterGenericSuperclassTest method imports_type_of_generic_superclass_with_parameterized_array_bounds.
@Test
public void imports_type_of_generic_superclass_with_parameterized_array_bounds() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
class Child extends BaseClass<List<String>[], List<String[]>[][], List<String[][]>[][][]> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).hasActualTypeArguments(genericArray(parameterizedTypeArrayName(List.class, String.class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String.class)), genericArray(parameterizedTypeArrayName(List.class, String[].class, 2)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[].class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String[].class))), genericArray(parameterizedTypeArrayName(List.class, String[][].class, 3)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[][].class, 2)).withComponentType(genericArray(parameterizedTypeArrayName(List.class, String[][].class, 1)).withComponentType(parameterizedType(List.class).withTypeArguments(String[][].class)))));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method references_outer_type_variable_assigned_to_actual_type_argument_of_generic_superclass_of_inner_class.
@Test
public void references_outer_type_variable_assigned_to_actual_type_argument_of_generic_superclass_of_inner_class() {
@SuppressWarnings("unused")
class OuterWithTypeParameter<OUTER extends String> {
class SomeInner {
@SuppressWarnings("unused")
class BaseClass<T> {
}
class Child extends BaseClass<OUTER> {
}
}
}
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(typeVariable("OUTER").withUpperBounds(String.class));
}
Aggregations