Search in sources :

Example 26 with EvaluationResult

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

the class ClassesShouldTest method beLocalClasses.

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

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

the class ClassesShouldTest method beEnums.

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

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

the class ClassesShouldTest method notBeTopLevelClasses.

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

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

the class ClassesShouldTest method onlyAccessFieldsThat.

@Test
@UseDataProvider("onlyAccessFieldsThat_rules")
public void onlyAccessFieldsThat(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithField.class, ClassAccessingField.class, ClassAccessingWrongField.class));
    assertThat(singleLineFailureReportOf(result)).contains("classes should only access fields that are declared in " + ClassWithField.class.getName()).containsPattern(accessesFieldRegex(ClassAccessingWrongField.class, "(sets|gets|accesses)", ClassAccessingField.class, "classWithField")).containsPattern(accessesFieldRegex(ClassAccessingField.class, "(sets|gets|accesses)", ClassAccessingField.class, "classWithField")).doesNotMatch(accessesFieldRegex(ClassAccessingField.class, "(sets|gets|accesses)", ClassWithField.class, "field")).doesNotMatch(accessesFieldRegex(ClassWithField.class, "(sets|gets|accesses)", ClassWithField.class, "field"));
}
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 30 with EvaluationResult

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

the class ClassesShouldTest method notImplement.

@Test
@UseDataProvider("notImplement_rules")
public void notImplement(ArchRule rule, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should not implement %s", Collection.class.getName())).containsPattern(String.format("Class <%s> implements %s in %s", quote(violated.getName()), quote(Collection.class.getName()), locationPattern(violated))).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)

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