use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class SlicesShouldTest method slice_rules_should_ignore_configured_dependencies.
@Test
@UseDataProvider("rules")
public void slice_rules_should_ignore_configured_dependencies(SliceRule rule) {
JavaClasses classes = new ClassFileImporter().importPackages(TEST_CLASSES_PACKAGE);
assertViolations(classes, rule).contain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(classIn(".*\\.first\\.three\\..*"), DescribedPredicate.<JavaClass>alwaysTrue());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(FirstAnyPkgClass.class.getName(), SomePkgSubclass.class.getName());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(SecondAnyClass.class, FirstAnyPkgClass.class);
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(DescribedPredicate.<JavaClass>alwaysTrue(), classIn(".*\\.some\\.pkg\\..*"));
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).doNotContain(SecondThreeAnyClass.class, SomePkgClass.class);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassCacheTest method filters_jars_relative_to_class.
@Test
public void filters_jars_relative_to_class() {
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, analyzePackagesOf(Rule.class));
assertThat(classes).isNotEmpty();
for (JavaClass clazz : classes) {
assertThat(clazz.getPackageName()).doesNotContain("tngtech");
}
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassGraphCreator method createEnclosingCodeUnit.
@Override
public Optional<JavaCodeUnit> createEnclosingCodeUnit(JavaClass owner) {
Optional<CodeUnit> enclosingCodeUnit = importRecord.getEnclosingCodeUnitFor(owner.getName());
if (!enclosingCodeUnit.isPresent()) {
return Optional.empty();
}
CodeUnit codeUnit = enclosingCodeUnit.get();
JavaClass enclosingClass = classes.getOrResolve(codeUnit.getDeclaringClassName());
return enclosingClass.tryGetCodeUnitWithParameterTypeNames(codeUnit.getName(), codeUnit.getRawParameterTypeNames());
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ImportedClasses method resolve.
private JavaClass resolve(String typeName) {
Optional<JavaClass> resolved = resolver.tryResolve(typeName);
JavaClass javaClass = resolved.isPresent() ? resolved.get() : stubClassOf(typeName);
if (javaClass.isArray()) {
ensureAllComponentTypesPresent(javaClass);
}
allClasses.put(typeName, javaClass);
return javaClass;
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method does_not_add_synthetic_lambda_methods_to_classes.
@Test
public void does_not_add_synthetic_lambda_methods_to_classes() {
class Target {
void target() {
}
}
@SuppressWarnings("unused")
class Caller {
@SuppressWarnings("Convert2MethodRef")
Runnable call(Target target) {
return () -> target.target();
}
}
JavaClass caller = new ClassFileImporter().importClasses(Target.class, Caller.class).get(Caller.class);
assertThat(caller.getMethods()).doNotHave(syntheticLambdaMethods()).hasSize(1);
}
Aggregations