Search in sources :

Example 21 with JavaClasses

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

the class ClassCacheTest method when_there_are_only_nonexisting_sources_nothing_is_imported.

@Test
@UseDataProvider("test_classes_without_any_imported_classes")
public void when_there_are_only_nonexisting_sources_nothing_is_imported(TestAnalysisRequest analysisRequest) {
    JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, analysisRequest);
    assertThat(classes).isEmpty();
    verify(cacheClassFileImporter).importClasses(any(ImportOptions.class), locationCaptor.capture());
    assertThat(locationCaptor.getValue()).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ImportOptions(com.tngtech.archunit.core.importer.ImportOptions) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 22 with JavaClasses

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

the class ClassCacheTest method gets_all_classes_relative_to_class.

@Test
public void gets_all_classes_relative_to_class() {
    JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, analyzePackagesOf(getClass()));
    assertThat(classes).isNotEmpty();
    assertThat(classes.contain(getClass())).as("root class is contained itself").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 23 with JavaClasses

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

the class ClassCache method getClassesToAnalyzeFor.

JavaClasses getClassesToAnalyzeFor(Class<?> testClass, ClassAnalysisRequest classAnalysisRequest) {
    checkNotNull(testClass);
    checkNotNull(classAnalysisRequest);
    if (cachedByTest.containsKey(testClass)) {
        return cachedByTest.get(testClass);
    }
    LocationsKey locations = RequestedLocations.by(classAnalysisRequest, testClass).asKey();
    JavaClasses classes = classAnalysisRequest.getCacheMode() == FOREVER ? cachedByLocations.getUnchecked(locations).get() : new LazyJavaClasses(locations.locations, locations.importOptionTypes).get();
    cachedByTest.put(testClass, classes);
    return classes;
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses)

Example 24 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project jhipster-sample-app-react by jhipster.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("io.github.jhipster.sample");
    noClasses().that().resideInAnyPackage("io.github.jhipster.sample.service..").or().resideInAnyPackage("io.github.jhipster.sample.repository..").should().dependOnClassesThat().resideInAnyPackage("..io.github.jhipster.sample.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 25 with JavaClasses

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

the class JetSerializableTest method serializable_classes_should_have_valid_serialVersionUID.

@Test
public void serializable_classes_should_have_valid_serialVersionUID() {
    String basePackage = JetService.class.getPackage().getName();
    JavaClasses classes = new ClassFileImporter().withImportOption(onlyCurrentModule()).importPackages(basePackage);
    ArchUnitRules.SERIALIZABLE_SHOULD_HAVE_VALID_SERIAL_VERSION_UID.check(classes);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) 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