use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method considers_hierarchy_of_methods_and_classes_for_type_parameter_context.
@Test
public void considers_hierarchy_of_methods_and_classes_for_type_parameter_context() throws ClassNotFoundException {
@SuppressWarnings("unused")
class Level1<T1 extends String> {
<T2 extends T1> void level2() {
class BaseClass<T> {
}
class Level3<T3 extends T2> extends BaseClass<T3> {
}
}
}
Class<?> innermostClass = Class.forName(Level1.class.getName() + "$1Level3");
JavaType genericSuperclass = importClassesWithOnlyGenericTypeResolution(innermostClass, Level1.class).get(innermostClass).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(typeVariable("T3").withUpperBounds(typeVariable("T2").withUpperBounds(typeVariable("T1").withUpperBounds(String.class))));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_generic_superclass_of_inner_class.
@Test
public void creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_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 = resetConfigurationAround(() -> {
ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
return importClassWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.Child.class).getSuperclass().get();
});
;
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(typeVariable("OUTER").withoutUpperBounds());
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_actual_type_argument_parameterized_with_type_variable.
@Test
public void imports_generic_superclass_with_actual_type_argument_parameterized_with_type_variable() {
@SuppressWarnings("unused")
class BaseClass<SUPER> {
}
class Child<SUB> extends BaseClass<ClassParameterWithSingleTypeParameter<SUB>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(typeVariable("SUB")));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_single_actual_type_argument_parameterized_with_concrete_class.
@Test
public void imports_generic_superclass_with_single_actual_type_argument_parameterized_with_concrete_class() {
@SuppressWarnings("unused")
class BaseClass<T> {
}
class Child extends BaseClass<ClassParameterWithSingleTypeParameter<String>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(String.class));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method creates_new_stub_type_variables_for_wildcards_bound_by_type_variables_of_enclosing_classes_that_are_out_of_context.
@Test
public void creates_new_stub_type_variables_for_wildcards_bound_by_type_variables_of_enclosing_classes_that_are_out_of_context() {
@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 = resetConfigurationAround(() -> {
ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
return importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.Child.class, ClassParameterWithSingleTypeParameter.class).get(OuterWithTypeParameter.SomeInner.Child.class).getSuperclass().get();
});
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("OUTER_ONE").withoutUpperBounds()), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("OUTER_TWO").withoutUpperBounds()));
}
Aggregations