Search in sources :

Example 76 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterSlowTest method imports_jars.

@Test
public void imports_jars() throws Exception {
    JavaClasses classes = new ClassFileImporter().importJar(jarFileOf(Rule.class));
    assertThatTypes(classes).contain(Rule.class);
    assertThatTypes(classes).doNotContain(Object.class, ImmutableList.class);
    classes = new ClassFileImporter().importJars(jarFileOf(Rule.class), jarFileOf(ImmutableList.class));
    assertThatTypes(classes).contain(Rule.class, ImmutableList.class);
    assertThatTypes(classes).doNotContain(Object.class);
    classes = new ClassFileImporter().importJars(ImmutableList.of(jarFileOf(Rule.class), jarFileOf(ImmutableList.class)));
    assertThatTypes(classes).contain(Rule.class, ImmutableList.class);
    assertThatTypes(classes).doNotContain(Object.class);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ImmutableList(com.google.common.collect.ImmutableList) SystemPropertiesRule(com.tngtech.archunit.testutil.SystemPropertiesRule) TransientCopyRule(com.tngtech.archunit.testutil.TransientCopyRule) ContextClassLoaderRule(com.tngtech.archunit.testutil.ContextClassLoaderRule) Rule(org.junit.Rule) Test(org.junit.Test)

Example 77 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterSlowTest method imports_packages.

@Test
public void imports_packages() {
    JavaClasses classes = new ClassFileImporter().importPackages(getClass().getPackage().getName(), Rule.class.getPackage().getName());
    assertThatTypes(classes).contain(ImmutableSet.of(getClass(), Rule.class));
    classes = new ClassFileImporter().importPackages(ImmutableSet.of(getClass().getPackage().getName(), Rule.class.getPackage().getName()));
    assertThatTypes(classes).contain(ImmutableSet.of(getClass(), Rule.class));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SystemPropertiesRule(com.tngtech.archunit.testutil.SystemPropertiesRule) TransientCopyRule(com.tngtech.archunit.testutil.TransientCopyRule) ContextClassLoaderRule(com.tngtech.archunit.testutil.ContextClassLoaderRule) Rule(org.junit.Rule) Test(org.junit.Test)

Example 78 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterSlowTest method creates_JavaPackages.

@Test
public void creates_JavaPackages() {
    JavaClasses javaClasses = importJavaBase();
    JavaPackage defaultPackage = javaClasses.getDefaultPackage();
    assertThat(defaultPackage.containsPackage("java")).as("Created default package contains 'java'").isTrue();
    JavaPackage javaPackage = defaultPackage.getPackage("java.lang");
    assertThatTypes(javaPackage.getClasses()).contain(Object.class, String.class, Integer.class);
    assertThatTypes(javaPackage.getAllClasses()).contain(Object.class, Annotation.class, Field.class);
    assertThat(javaClasses.containPackage("java.util")).as("Classes contain package 'java.util'").isTrue();
    assertThatTypes(javaClasses.getPackage("java.util").getClasses()).contain(List.class);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) Test(org.junit.Test)

Example 79 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterSlowTest method imports_the_classpath.

@Test
public void imports_the_classpath() {
    JavaClasses classes = new ClassFileImporter().importClasspath();
    assertThatTypes(classes).contain(ClassFileImporter.class, getClass());
    // Default does not import jars
    assertThatTypes(classes).doNotContain(Rule.class);
    // Default does not import JDK classes
    assertThatTypes(classes).doNotContain(File.class);
    classes = new ClassFileImporter().importClasspath(new ImportOptions().with(importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath()));
    assertThatTypes(classes).contain(ClassFileImporter.class, getClass(), Rule.class, File.class);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 80 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterSlowTest method imports_packages_of_classes.

@Test
public void imports_packages_of_classes() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass(), Rule.class);
    assertThatTypes(classes).contain(ImmutableSet.of(getClass(), Rule.class));
    classes = new ClassFileImporter().importPackagesOf(ImmutableSet.of(getClass(), Rule.class));
    assertThatTypes(classes).contain(ImmutableSet.of(getClass(), Rule.class));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SystemPropertiesRule(com.tngtech.archunit.testutil.SystemPropertiesRule) TransientCopyRule(com.tngtech.archunit.testutil.TransientCopyRule) ContextClassLoaderRule(com.tngtech.archunit.testutil.ContextClassLoaderRule) Rule(org.junit.Rule) Test(org.junit.Test)

Aggregations

JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)248 Test (org.junit.Test)184 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)98 JavaClass (com.tngtech.archunit.core.domain.JavaClass)72 Test (org.junit.jupiter.api.Test)54 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)19 ArchRule (com.tngtech.archunit.lang.ArchRule)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)15 MethodCallTarget (com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 JavaConstructorCall (com.tngtech.archunit.core.domain.JavaConstructorCall)12 Set (java.util.Set)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10