use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class JavaTypeAssertion method hasActualTypeArguments.
public void hasActualTypeArguments(ExpectedConcreteType... typeArguments) {
assertThat(actual).isInstanceOf(JavaParameterizedType.class);
JavaParameterizedType parameterizedType = (JavaParameterizedType) this.actual;
List<JavaType> actualTypeArguments = parameterizedType.getActualTypeArguments();
DescriptionContext context = new DescriptionContext(actual.getName()).describeTypeParameters().step("actual type arguments");
assertThat(actualTypeArguments).as(context.toString()).hasSameSizeAs(typeArguments);
for (int i = 0; i < actualTypeArguments.size(); i++) {
typeArguments[i].assertMatchWith(actualTypeArguments.get(i), context.describeElement(i, actualTypeArguments.size()));
}
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_wildcards_of_generic_superclass_bound_by_type_variables.
@Test
public void imports_wildcards_of_generic_superclass_bound_by_type_variables() {
@SuppressWarnings("unused")
class BaseClass<A, B> {
}
class Child<FIRST extends String, SECOND extends Serializable> extends BaseClass<ClassParameterWithSingleTypeParameter<? extends FIRST>, ClassParameterWithSingleTypeParameter<? super SECOND>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasActualTypeArguments(parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithUpperBound(typeVariable("FIRST").withUpperBounds(String.class)), parameterizedType(ClassParameterWithSingleTypeParameter.class).withWildcardTypeParameterWithLowerBound(typeVariable("SECOND").withUpperBounds(Serializable.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_concrete_array_bounds.
@Test
public void imports_complex_type_with_multiple_nested_actual_type_arguments_of_generic_superclass_with_concrete_array_bounds() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
@SuppressWarnings("unused")
class Child extends BaseClass<List<Serializable[]>, List<? extends Serializable[][]>, Map<? super String[], Map<Map<? super String[][][], ?>, Serializable[][]>>> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).hasActualTypeArguments(parameterizedType(List.class).withTypeArguments(Serializable[].class), parameterizedType(List.class).withWildcardTypeParameterWithUpperBound(Serializable[][].class), 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 ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_multiple_type_arguments.
@Test
public void imports_generic_superclass_with_multiple_type_arguments() {
@SuppressWarnings("unused")
class BaseClass<A, B, C> {
}
@SuppressWarnings("unused")
class Child extends BaseClass<String, Serializable, File> {
}
JavaType genericSuperclass = importClassWithOnlyGenericTypeResolution(Child.class).getSuperclass().get();
assertThatType(genericSuperclass).as("generic superclass").hasErasure(BaseClass.class).hasActualTypeArguments(String.class, Serializable.class, File.class);
}
use of com.tngtech.archunit.core.domain.JavaType in project ArchUnit by TNG.
the class ClassFileImporterGenericSuperclassTest method imports_generic_superclass_with_array_type_argument.
@Test
public void imports_generic_superclass_with_array_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);
}
Aggregations