use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_containAnyCodeUnitsThat.
@Test
public void predicate_containAnyCodeUnitsThat() {
@SuppressWarnings("unused")
class Match {
void right() {
}
}
@SuppressWarnings("unused")
class Mismatch {
void wrong() {
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
assertThat(containAnyCodeUnitsThat(name("right"))).hasDescription("contain any code units that name 'right'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_containAnyFieldsThat.
@Test
public void predicate_containAnyFieldsThat() {
@SuppressWarnings("unused")
class Match {
String right;
}
@SuppressWarnings("unused")
class Mismatch {
String wrong;
}
JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
assertThat(containAnyFieldsThat(name("right"))).hasDescription("contain any fields that name 'right'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_belong_to.
@Test
public void predicate_belong_to() {
JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass());
JavaClass outerAnonymous = getOnlyClassSettingField(classes, ClassWithNamedAndAnonymousInnerClasses.name_of_fieldIndicatingOuterAnonymousInnerClass);
JavaClass nestedAnonymous = getOnlyClassSettingField(classes, ClassWithNamedAndAnonymousInnerClasses.name_of_fieldIndicatingNestedAnonymousInnerClass);
assertThat(belongToAnyOf(Object.class, ClassWithNamedAndAnonymousInnerClasses.class)).hasDescription(String.format("belong to any of [%s, %s]", Object.class.getName(), ClassWithNamedAndAnonymousInnerClasses.class.getName())).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.class)).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.NamedInnerClass.class)).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.NamedInnerClass.NestedNamedInnerClass.class)).accepts(outerAnonymous).accepts(nestedAnonymous).rejects(classes.get(getClass()));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_containAnyStaticInitializersThat.
@Test
public void predicate_containAnyStaticInitializersThat() {
@SuppressWarnings("unused")
class Mismatch {
}
JavaClasses classes = new ClassFileImporter().importClasses(Data_of_predicate_containAnyStaticInitializersThat.Match.class, Mismatch.class);
assertThat(containAnyStaticInitializersThat(DescribedPredicate.<JavaMember>alwaysTrue())).hasDescription("contain any static initializers that always true").accepts(classes.get(Data_of_predicate_containAnyStaticInitializersThat.Match.class)).rejects(classes.get(Mismatch.class));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_containAnyConstructorsThat.
@Test
public void predicate_containAnyConstructorsThat() {
@SuppressWarnings("unused")
class Match {
Match(Serializable param) {
}
}
@SuppressWarnings("unused")
class Mismatch {
Mismatch(String param) {
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
String regex = ".*" + Serializable.class.getSimpleName() + ".*";
assertThat(containAnyConstructorsThat(fullNameMatching(regex))).hasDescription("contain any constructors that full name matching '" + regex + "'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
Aggregations