Search in sources :

Example 6 with JavaClasses

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

the class ModuleDetectionStrategyUnitTest method detectsJMoleculesAnnotatedModule.

// #188
@Test
void detectsJMoleculesAnnotatedModule() {
    JavaClasses classes = // 
    new ClassFileImporter().withImportOption(// 
    new ImportOption.OnlyIncludeTests()).importPackages("jmolecules");
    JavaPackage javaPackage = JavaPackage.of(Classes.of(classes), "jmolecules");
    assertThat(ModuleDetectionStrategy.explictlyAnnotated().getModuleBasePackages(javaPackage)).containsExactly(javaPackage);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 7 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project arch-unit-build-plugin-core by societe-generale.

the class NoJavaUtilDateRuleTestTest method assertNoExceptionIsThrownFor.

private void assertNoExceptionIsThrownFor(Class clazz) {
    JavaClasses classToTest = new ClassFileImporter().importClasses(clazz);
    assertThatCode(() -> classes().should(NoJavaUtilDateRuleTest.notUseJavaUtilDate()).check(classToTest)).doesNotThrowAnyException();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter)

Example 8 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project arch-unit-build-plugin-core by societe-generale.

the class RuleInvokerService method invokeConfigurableRules.

private String invokeConfigurableRules(ConfigurableRule rule) {
    if (rule.isSkip()) {
        if (log.isInfoEnabled()) {
            log.info("Skipping rule " + rule.getRule());
        }
        return "";
    }
    InvokableRules invokableRules = InvokableRules.of(rule.getRule(), rule.getChecks(), log);
    String fullPathFromRootTopackage = getPackageNameOnWhichToApplyRules(rule);
    log.info("invoking ConfigurableRule " + rule.toString() + " on " + fullPathFromRootTopackage);
    JavaClasses classes = archUtils.importAllClassesInPackage(new RootClassFolder(""), fullPathFromRootTopackage, excludedPaths);
    InvocationResult result = invokableRules.invokeOn(classes);
    return result.getMessage();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) InvocationResult(com.societegenerale.commons.plugin.service.InvokableRules.InvocationResult) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder)

Example 9 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project arch-unit-build-plugin-core by societe-generale.

the class ArchUtilsTest method shouldIgnoreClassesFromConfiguredPaths.

@Test
public void shouldIgnoreClassesFromConfiguredPaths() {
    JavaClasses classes = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "");
    assertThat(classes).isNotEmpty();
    JavaClass classToExclude = classes.stream().filter(c -> c.getSource().get().getUri().toString().contains("ClassToExclude")).findFirst().get();
    assertThat(classToExclude).as("when no exclusion pattern configured, ClassToExclude should be found").isNotNull();
    JavaClasses classesWithTestClassesExclusions = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "", Arrays.asList("test-classes"));
    assertThat(containsClassWithPattern(classesWithTestClassesExclusions, "ClassToExclude")).as("when 'test-classes' pattern configured, ClassToExclude should still be found").isTrue();
    assertThat(classes.size()).as("There should be less classes loaded when we apply the test-classes exclusion").isGreaterThan(classesWithTestClassesExclusions.size());
    JavaClasses classesWithTestClassesAndSpecificExclusions = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "", Arrays.asList("test-classes", "ClassToExclude"));
    assertThat(containsClassWithPattern(classesWithTestClassesAndSpecificExclusions, "ClassToExclude")).as("when 'ClassToExclude' pattern configured, ClassToExclude should not  be found").isFalse();
    assertThat(classesWithTestClassesAndSpecificExclusions.size() + 1).as("with a specific exclusion; we should have one less class than without").isEqualTo(classesWithTestClassesExclusions.size());
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder) Test(org.junit.Test)

Example 10 with JavaClasses

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

the class MyArchitectureTests method ruleGeneralCodingRules.

@Test
public void ruleGeneralCodingRules() {
    ArchRule archRule = CompositeArchRule.of(GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS).and(NO_CLASSES_SHOULD_USE_FIELD_INJECTION).because("Good practice");
    JavaClasses classesToCheck = this.importedClasses.that(JavaClass.Predicates.resideOutsideOfPackages("..adapter.clients.test.."));
    archRule.check(classesToCheck);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) CompositeArchRule(com.tngtech.archunit.lang.CompositeArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArchTest(com.tngtech.archunit.junit.ArchTest) Test(org.junit.jupiter.api.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