Search in sources :

Example 91 with EvaluationResult

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

the class ClassesShouldTest method notVisibility.

@Test
@UseDataProvider("not_visibility_rules")
public void notVisibility(ArchRule rule, JavaModifier modifier, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should not be %s", modifier.name().toLowerCase())).containsPattern(String.format("Class <%s> .* modifier %s", quote(violated.getName()), modifier)).doesNotMatch(String.format(".*<%s>.* modifier %s.*", quote(satisfied.getName()), modifier));
}
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 92 with EvaluationResult

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

the class ClassesShouldTest method implement_satisfied.

@Test
@UseDataProvider("implement_satisfied_rules")
public void implement_satisfied(ArchRule rule, Class<?> satisfied) {
    EvaluationResult result = rule.evaluate(importHierarchies(satisfied));
    assertThat(singleLineFailureReportOf(result)).doesNotMatch(String.format(".*%s.* implement.*", 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 93 with EvaluationResult

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

the class ClassesShouldTest method resideInAPackage.

@Test
@UseDataProvider("resideInAPackage_rules")
public void resideInAPackage(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 in a package '%s'", packageIdentifier)).containsPattern(doesntResideInAPackagePatternFor(ArchConfiguration.class, packageIdentifier)).containsPattern(doesntResideInAPackagePatternFor(GivenObjects.class, packageIdentifier)).doesNotContain(String.format("%s", ArchRule.class.getSimpleName())).doesNotContain(String.format("%s", ArchCondition.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 94 with EvaluationResult

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

the class ClassesShouldTest method haveFullyQualifiedName.

@Test
@UseDataProvider("haveFullyQualifiedName_rules")
public void haveFullyQualifiedName(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have fully qualified name '%s'", SomeClass.class.getName())).containsPattern(String.format("Class <%s> does not have fully qualified name '%s' in %s", quote(WrongNamedClass.class.getName()), quote(SomeClass.class.getName()), locationPattern(WrongNamedClass.class))).doesNotMatch(String.format(".*<%s>.*name.*", quote(SomeClass.class.getName())));
}
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 95 with EvaluationResult

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

the class ClassesShouldTest method notHaveFullyQualifiedName.

@Test
@UseDataProvider("notHaveFullyQualifiedName_rules")
public void notHaveFullyQualifiedName(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should not have fully qualified name '%s'", WrongNamedClass.class.getName())).contains(String.format("Class <%s> has fully qualified name '%s'", WrongNamedClass.class.getName(), WrongNamedClass.class.getName())).doesNotContain(String.format("<%s>.*name", SomeClass.class.getName()));
}
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)

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