Search in sources :

Example 81 with EvaluationResult

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

the class ClassesShouldTest method notBeEnums.

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

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

the class ClassesShouldTest method notAssignableFrom.

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

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

the class ClassesShouldTest method haveSimpleNameNotContaining.

@Test
@UseDataProvider("haveSimpleNameNotContaining_rules")
public void haveSimpleNameNotContaining(ArchRule rule, String infix) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name not containing '%s'", infix)).containsPattern(String.format("simple name of %s contains '%s' in %s", quote(WrongNamedClass.class.getName()), quote(infix), 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 84 with EvaluationResult

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

the class ClassesShouldTest method modifiers.

@Test
@UseDataProvider("modifiers_rules")
public void modifiers(ArchRule rule, String havePrefix, JavaModifier modifier, Class<?> satisfied, Class<?> violated) {
    EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should %shave modifier %s", havePrefix, modifier.name())).containsPattern(String.format("Class <%s> .* modifier %s in %s", quote(violated.getName()), modifier, // -> location == enclosingClass()
    locationPattern(getClass()))).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 85 with EvaluationResult

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

the class ClassesShouldTest method haveNameMatching.

@Test
@UseDataProvider("haveNameMatching_rules")
public void haveNameMatching(ArchRule rule, String regex) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have name matching '%s'", regex)).containsPattern(String.format("Class <%s> does not match '%s' in %s", quote(WrongNamedClass.class.getName()), quote(regex), locationPattern(WrongNamedClass.class))).doesNotContain(String.format("%s", SomeClass.class.getSimpleName()));
}
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