use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest 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 GenericFieldType<A, B> {
}
class SomeClass {
GenericFieldType<ClassParameterWithSingleTypeParameter<? extends OUTER_ONE>, ClassParameterWithSingleTypeParameter<? super OUTER_TWO>> field;
}
}
}
JavaType genericFieldType = resetConfigurationAround(() -> {
ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
return importClassesWithOnlyGenericTypeResolution(OuterWithTypeParameter.SomeInner.SomeClass.class, ClassParameterWithSingleTypeParameter.class).get(OuterWithTypeParameter.SomeInner.SomeClass.class).getField("field").getType();
});
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("OUTER_ONE").withoutUpperBounds()), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("OUTER_TWO").withoutUpperBounds()));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_actual_type_argument_parameterized_with_type_variable.
@Test
public void imports_generic_field_type_with_actual_type_argument_parameterized_with_type_variable() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass<OF_CLASS> {
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")));
}
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_concrete_class.
@Test
public void imports_generic_field_type_with_single_actual_type_argument_parameterized_with_concrete_class() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<ClassParameterWithSingleTypeParameter<String>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(String.class));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_complex_generic_array_field_type.
@Test
public void imports_complex_generic_array_field_type() {
@SuppressWarnings("unused")
class GenericFieldType<A> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<Map<? super String, Map<Map<? super String, ?>, Serializable>>>[] field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).matches(genericArray(GenericFieldType.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", " + Map.class.getName() + "<" + Map.class.getName() + "<? super " + String.class.getName() + ", ?>, " + Serializable.class.getName() + ">>>[]").withComponentType(parameterizedType(GenericFieldType.class).withTypeArguments(parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(String.class), parameterizedType(Map.class).withTypeArguments(parameterizedType(Map.class).withTypeArguments(wildcardType().withLowerBound(String.class), wildcardType()), concreteClass(Serializable.class))))));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_non_generic_field_type.
@Test
public void imports_non_generic_field_type() {
class NonGenericFieldType {
}
@SuppressWarnings("unused")
class SomeClass {
NonGenericFieldType field;
}
JavaType fieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(fieldType).as("generic field type").matches(NonGenericFieldType.class);
}
Aggregations