Search in sources :

Example 46 with EvaluationResult

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

the class ClassesShouldTest method assignableTo.

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

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

the class ClassesShouldTest method notBeLocalClasses.

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

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

the class ClassesShouldTest method beMemberClasses.

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

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

the class ClassesShouldTest method callConstructor.

@Test
@UseDataProvider("callConstructor_rules")
public void callConstructor(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithConstructor.class, ClassCallingConstructor.class, ClassCallingWrongConstructor.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call constructor %s.<init>(%s)", ClassWithConstructor.class.getSimpleName(), String.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)

Example 50 with EvaluationResult

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

the class ClassesShouldTest method notAnnotatedWith.

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