use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_generic_field_type_of_inner_class.
@Test
public void creates_new_stub_type_variables_for_type_variables_of_enclosing_classes_that_are_out_of_context_for_generic_field_type_of_inner_class() {
@SuppressWarnings("unused")
class OuterWithTypeParameter<OUTER extends String> {
class SomeInner {
class GenericFieldType<T> {
}
class SomeClass {
GenericFieldType<OUTER> field;
}
}
}
JavaType genericFieldType = resetConfigurationAround(() -> {
ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
return importClassWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.SomeClass.class).getField("field").getType();
});
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(typeVariable("OUTER").withoutUpperBounds());
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method references_type_variable_assigned_to_actual_type_argument_of_generic_field_type.
@Test
public void references_type_variable_assigned_to_actual_type_argument_of_generic_field_type() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass<OF_CLASS extends String> {
GenericFieldType<ClassParameterWithSingleTypeParameter<OF_CLASS>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(typeVariable("OF_CLASS").withUpperBounds(String.class)));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_parameterized_with_type_variable.
@Test
public void imports_generic_field_type_parameterized_with_type_variable() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass<OF_CLASS> {
GenericFieldType<OF_CLASS> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(typeVariable("OF_CLASS"));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_multiple_type_arguments.
@Test
public void imports_generic_field_type_with_multiple_type_arguments() {
@SuppressWarnings("unused")
class GenericFieldType<A, B, C> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<String, Serializable, File> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasErasure(GenericFieldType.class).hasActualTypeArguments(String.class, Serializable.class, File.class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_wildcards_of_generic_field_type_bound_by_type_variables.
@Test
public void imports_wildcards_of_generic_field_type_bound_by_type_variables() {
@SuppressWarnings("unused")
class GenericFieldType<A, B> {
}
@SuppressWarnings("unused")
class SomeClass<FIRST extends String, SECOND extends Serializable> {
GenericFieldType<ClassParameterWithSingleTypeParameter<? extends FIRST>, ClassParameterWithSingleTypeParameter<? super SECOND>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("SECOND").withUpperBounds(Serializable.class)));
}
Aggregations