Search in sources :

Example 31 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method callMethodWhere.

@Test
@UseDataProvider("callMethodWhere_rules")
public void callMethodWhere(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithMethod.class, ClassCallingMethod.class, ClassCallingWrongMethod.class, ClassCallingSelf.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call method where target is %s", ClassWithMethod.class.getSimpleName())).containsPattern(callMethodRegex(ClassCallingWrongMethod.class, ClassCallingMethod.class, "call")).containsPattern(callMethodRegex(ClassCallingSelf.class, ClassCallingSelf.class, "target")).doesNotMatch(callMethodRegex(ClassCallingMethod.class, ClassWithMethod.class, "method", String.class));
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 32 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method onlyCallCodeUnitsThat.

@Test
@UseDataProvider("onlyCallCodeUnitsThat_rules")
public void onlyCallCodeUnitsThat(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, ClassAccessingWrongFieldMethodAndConstructor.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should only call code units that are declared in %s", ClassWithFieldMethodAndConstructor.class.getName())).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, CONSTRUCTOR_NAME, int.class, Date.class)).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "call")).doesNotMatch(accessesFieldRegex(ClassAccessingWrongFieldMethodAndConstructor.class, "sets", ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callCodeUnitRegex(ClassAccessingFieldMethodAndConstructor.class, ClassWithFieldMethodAndConstructor.class, ""));
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Date(java.util.Date) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 33 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method haveNameNotMatching.

@Test
@UseDataProvider("haveNameNotMatching_rules")
public void haveNameNotMatching(ArchRule rule, String regex) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have name not matching '%s'", regex)).containsPattern(String.format("Class <%s> matches '%s' in %s", quote(WrongNamedClass.class.getName()), quote(regex), locationPattern(WrongNamedClass.class))).doesNotContain(String.format("%s", SomeClass.class.getSimpleName()));
}
Also used : SomeClass(com.tngtech.archunit.lang.syntax.elements.testclasses.SomeClass) WrongNamedClass(com.tngtech.archunit.lang.syntax.elements.testclasses.WrongNamedClass) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 34 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method resideOutsideOfPackage.

@Test
@UseDataProvider("resideOutsideOfPackage_rules")
public void resideOutsideOfPackage(ArchRule rule, String packageIdentifier) {
    checkTestStillValid(packageIdentifier, ImmutableSet.of(ArchRule.class, ArchCondition.class), ImmutableSet.<Class<?>>of(ArchConfiguration.class), ImmutableSet.<Class<?>>of(GivenObjects.class));
    EvaluationResult result = rule.evaluate(importClasses(ArchRule.class, ArchCondition.class, ArchConfiguration.class, GivenObjects.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should reside outside of package '%s'", packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchRule.class, packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchCondition.class, packageIdentifier)).doesNotContain(String.format("%s", ArchConfiguration.class.getSimpleName())).doesNotContain(String.format("%s", GivenObjects.class.getSimpleName()));
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) ArchCondition(com.tngtech.archunit.lang.ArchCondition) ArchConfiguration(com.tngtech.archunit.ArchConfiguration) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 35 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method notMetaAnnotatedWith.

@Test
@UseDataProvider("notMetaAnnotated_rules")
public void notMetaAnnotatedWith(ArchRule rule, Class<?> correctClass, Class<?> wrongClass) {
    EvaluationResult result = rule.evaluate(importClasses(correctClass, wrongClass));
    assertThat(singleLineFailureReportOf(result)).contains("classes should not be meta-annotated with @" + SomeMetaAnnotation.class.getSimpleName()).containsPattern(String.format("Class <%s> is meta-annotated with @%s in %s", quote(wrongClass.getName()), SomeMetaAnnotation.class.getSimpleName(), locationPattern(getClass()))).doesNotMatch(String.format(".*<%s>.*meta-annotated.*", quote(correctClass.getName())));
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)140 Test (org.junit.Test)132 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)107 CanBeAnnotatedTest (com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest)63 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)13 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)13 SomeClass (com.tngtech.archunit.lang.syntax.elements.testclasses.SomeClass)12 WrongNamedClass (com.tngtech.archunit.lang.syntax.elements.testclasses.WrongNamedClass)12 ArchCondition (com.tngtech.archunit.lang.ArchCondition)7 ArchRule (com.tngtech.archunit.lang.ArchRule)6 FailureReport (com.tngtech.archunit.lang.FailureReport)6 ClassWithVariousMembers (com.tngtech.archunit.lang.syntax.elements.GivenCodeUnitsTest.ClassWithVariousMembers)6 SimpleFieldAndMethod (com.tngtech.archunit.lang.syntax.elements.testclasses.SimpleFieldAndMethod)6 ArchTest (com.tngtech.archunit.junit.ArchTest)5 OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)5 ArchConfiguration (com.tngtech.archunit.ArchConfiguration)4 JavaMember (com.tngtech.archunit.core.domain.JavaMember)4 ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)4 ClassWithVariousMembers (com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.ClassWithVariousMembers)3 Date (java.util.Date)3