Search in sources :

Example 76 with EvaluationResult

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

the class ClassesShouldTest method notBeMemberClasses.

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

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

the class ClassesShouldTest method beClass.

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

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

the class ClassesShouldTest method notBeNestedClasses.

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

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

the class ClassesShouldTest method metaAnnotatedWith.

@Test
@UseDataProvider("metaAnnotated_rules")
public void metaAnnotatedWith(ArchRule rule, Class<?> correctClass, Class<?> wrongClass) {
    EvaluationResult result = rule.evaluate(importClasses(correctClass, wrongClass));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should be meta-annotated with @%s", SomeMetaAnnotation.class.getSimpleName())).containsPattern(String.format("Class <%s> is not meta-annotated with @%s in %s", quote(wrongClass.getName()), SomeMetaAnnotation.class.getSimpleName(), locationPattern(String.class))).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)

Example 80 with EvaluationResult

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

the class ClassesShouldTest method annotatedWith.

@Test
@UseDataProvider("annotated_rules")
public void annotatedWith(ArchRule rule, Class<?> correctClass, Class<?> wrongClass) {
    EvaluationResult result = rule.evaluate(importClasses(correctClass, wrongClass));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should be annotated with @%s", RuntimeRetentionAnnotation.class.getSimpleName())).containsPattern(String.format("Class <%s> is not annotated with @%s in %s", quote(wrongClass.getName()), RuntimeRetentionAnnotation.class.getSimpleName(), locationPattern(String.class))).doesNotMatch(String.format(".*<%s>.*annotated.*", quote(correctClass.getName())));
}
Also used : RuntimeRetentionAnnotation(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest.RuntimeRetentionAnnotation) 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