Search in sources :

Example 71 with EvaluationResult

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

the class HandlingAssertion method evaluate.

Result evaluate(EvaluationResult evaluationResult) {
    Result result = new Result();
    result.addAll(evaluateFieldAccesses(evaluationResult));
    result.addAll(evaluateMethodCalls(evaluationResult));
    result.addAll(evaluateConstructorCalls(evaluationResult));
    result.addAll(evaluateCalls(evaluationResult));
    result.addAll(evaluateAccesses(evaluationResult));
    result.addAll(evaluateDependencies(evaluationResult));
    return result;
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult)

Example 72 with EvaluationResult

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

the class ClassesShouldTest method notBeInnerClasses.

@Test
@UseDataProvider("notBeInnerClasses_rules")
public void notBeInnerClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains("classes should not be inner classes").containsPattern(String.format("Class <%s> is an inner class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* inner class.*", quote(satisfied.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)

Example 73 with EvaluationResult

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

the class ClassesShouldTest method notBeAnonymousClasses.

@Test
@UseDataProvider("notBeAnonymousClasses_rules")
public void notBeAnonymousClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains("classes should not be anonymous classes").containsPattern(String.format("Class <%s> is an anonymous class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* anonymous class.*", quote(satisfied.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)

Example 74 with EvaluationResult

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

the class ClassesShouldTest method notBeClass.

@Test
@UseDataProvider("notBeClass_rules")
public void notBeClass(ArchRule rule, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains("classes should not be " + violated.getName()).containsPattern(String.format("Class <%s> is %s in %s", quote(violated.getName()), quote(violated.getName()), locationPattern(violated))).doesNotMatch(String.format(".*%s.* is .*", quote(satisfied.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)

Example 75 with EvaluationResult

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

the class ClassesShouldTest method callConstructorWhere.

@Test
@UseDataProvider("callConstructorWhere_rules")
public void callConstructorWhere(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithConstructor.class, ClassCallingConstructor.class, ClassCallingWrongConstructor.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call constructor where target is %s", ClassWithConstructor.class.getSimpleName())).containsPattern(callConstructorRegex(ClassCallingWrongConstructor.class, ClassCallingConstructor.class, int.class, Date.class)).doesNotMatch(callConstructorRegex(ClassCallingConstructor.class, ClassWithConstructor.class, 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)

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