Search in sources :

Example 36 with EvaluationResult

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

the class ClassesShouldTest method haveSimpleNameStartingWith.

@Test
@UseDataProvider("haveSimpleNameStartingWith_rules")
public void haveSimpleNameStartingWith(ArchRule rule, String prefix) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name starting with '%s'", prefix)).containsPattern(String.format("simple name of %s does not start with '%s' in %s", quote(WrongNamedClass.class.getName()), quote(prefix), locationPattern(WrongNamedClass.class))).doesNotContain(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 37 with EvaluationResult

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

the class ClassesShouldTest method onlyCallConstructorsThat.

@Test
@UseDataProvider("onlyCallConstructorsThat_rules")
public void onlyCallConstructorsThat(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(ClassWithConstructor.class, ClassCallingConstructor.class, ClassCallingWrongConstructor.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should only call constructors that are declared in %s", ClassWithConstructor.class.getName())).containsPattern(callConstructorRegex(ClassCallingWrongConstructor.class, ClassCallingConstructor.class, int.class, Date.class)).doesNotMatch(accessesFieldRegex(ClassAccessingWrongFieldMethodAndConstructor.class, "sets", ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callConstructorRegex(ClassCallingConstructor.class, ClassWithConstructor.class, String.class));
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Date(java.util.Date) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 38 with EvaluationResult

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

the class ClassesShouldTest method non_package_private_visibility.

@Test
@UseDataProvider("non_package_private_visibility_rules")
public void non_package_private_visibility(ArchRule rule, String description) {
    EvaluationResult result = rule.evaluate(importClasses(PrivateClass.class, PackagePrivateClass.class));
    assertThat(singleLineFailureReportOf(result)).contains("classes should " + description).contains(String.format("Class <%s>", PackagePrivateClass.class.getName())).contains("does not have modifier " + PUBLIC).contains("does not have modifier " + PROTECTED).contains("does not have modifier " + PRIVATE).doesNotMatch(String.format(".*<%s>.* modifier.*", quote(PrivateClass.class.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 39 with EvaluationResult

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

the class ClassesShouldTest method haveSimpleNameNotEndingWith.

@Test
@UseDataProvider("haveSimpleNameNotEndingWith_rules")
public void haveSimpleNameNotEndingWith(ArchRule rule, String suffix) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name not ending with '%s'", suffix)).containsPattern(String.format("simple name of %s ends with '%s' in %s", quote(WrongNamedClass.class.getName()), quote(suffix), locationPattern(WrongNamedClass.class))).doesNotContain(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 40 with EvaluationResult

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

the class ClassesShouldTest method package_private_visibility.

@Test
@UseDataProvider("package_private_visibility_rules")
public void package_private_visibility(ArchRule rule, String description) {
    EvaluationResult result = rule.evaluate(importClasses(PackagePrivateClass.class, PrivateClass.class));
    assertThat(singleLineFailureReportOf(result)).contains("classes should " + description).containsPattern(String.format("Class <%s> .* modifier %s", quote(PrivateClass.class.getName()), PRIVATE)).doesNotMatch(String.format(".*<%s>.* modifier.*", quote(PackagePrivateClass.class.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