use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_parameterized_array_bounds.
@Test
public void imports_generic_field_type_with_parameterized_array_bounds() {
@SuppressWarnings("unused")
class GenericFieldType<A, B, C> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<List<String>[], List<String[]>[][], List<String[][]>[][][]> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).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 ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_array_type_argument.
@Test
public void imports_generic_field_type_with_array_type_argument() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<String[]> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasErasure(GenericFieldType.class).hasActualTypeArguments(String[].class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest 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 Level3<T3 extends T2> {
T3 field;
}
}
}
Class<?> innermostClass = Class.forName(Level1.class.getName() + "$1Level3");
JavaType genericFieldType = importClassesWithOnlyGenericTypeResolution(innermostClass, Level1.class).get(innermostClass).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").matches(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 ClassFileImporterGenericFieldTypesTest method imports_complex_generic_field_type_with_multiple_nested_actual_type_arguments_with_generic_array_bounds.
@Test
public void imports_complex_generic_field_type_with_multiple_nested_actual_type_arguments_with_generic_array_bounds() {
@SuppressWarnings("unused")
class GenericFieldType<A, B, C> {
}
@SuppressWarnings("unused")
class SomeClass<X extends Serializable, Y extends String> {
GenericFieldType<List<X[]>, List<? extends X[][]>, Map<? super Y[], Map<Map<? super Y[][][], ?>, X[][]>>> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).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))))));
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericFieldTypesTest method imports_generic_field_type_with_single_unbound_wildcard.
@Test
public void imports_generic_field_type_with_single_unbound_wildcard() {
@SuppressWarnings("unused")
class GenericFieldType<T> {
}
@SuppressWarnings("unused")
class SomeClass {
GenericFieldType<?> field;
}
JavaType genericFieldType = importClassWithOnlyGenericTypeResolution(SomeClass.class).getField("field").getType();
assertThatType(genericFieldType).as("generic field type").hasActualTypeArguments(wildcardType());
}
Aggregations