com.tngtech.java.junit.dataprovider.UseDataProvider Java Examples

The following examples show how to use com.tngtech.java.junit.dataprovider.UseDataProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("resideOutsideOfPackages_rules")
public void resideOutsideOfPackages(ArchRule rule, String... packageIdentifiers) {
    checkTestStillValid(packageIdentifiers,
            ImmutableSet.of(ArchRule.class, ArchConfiguration.class),
            ImmutableSet.<Class<?>>of(GivenObjects.class));

    EvaluationResult result = rule.evaluate(importClasses(
            ArchRule.class, ArchCondition.class, ArchConfiguration.class, GivenObjects.class));

    assertThat(singleLineFailureReportOf(result))
            .contains(String.format("classes should reside outside of packages ['%s']",
                    Joiner.on("', '").join(packageIdentifiers)))
            .containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchRule.class, packageIdentifiers))
            .containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchCondition.class, packageIdentifiers))
            .doesNotContain(String.format("%s", GivenObjects.class.getSimpleName()));
}
 
Example #2
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("theClass_should_resideInAnyPackage_rules")
public void theClass_should_resideInAnyPackage(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    String firstPackage = SomeClass.class.getPackage().getName();
    String secondPackage = Object.class.getPackage().getName();
    String[] packageIdentifiers = {firstPackage, secondPackage};

    assertThatRules(satisfiedRule, unsatisfiedRule, SomeClass.class, Object.class)
            .haveSuccessfulRuleText("the class %s should reside in any package ['%s']",
                    SomeClass.class.getName(),
                    Joiner.on("', '").join(packageIdentifiers))
            .haveFailingRuleText("the class %s should reside outside of packages ['%s']",
                    SomeClass.class.getName(),
                    Joiner.on("', '").join(packageIdentifiers))
            .containFailureDetail(String.format("Class <%s> does not reside outside of packages \\['%s'\\] in %s",
                    quote(SomeClass.class.getName()),
                    quote(Joiner.on("', '").join(packageIdentifiers)),
                    locationPattern(SomeClass.class)))
            .doNotContainFailureDetail(quote(Object.class.getName()));
}
 
Example #3
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("callConstructorWhere_rules")
public void callConstructorWhere(ArchRule rule) {
    EvaluationResult result = rule.evaluate(importClasses(
            ClassWithConstructor.class, ClassCallingConstructor.class, ClassCallingWrongConstructor.class));

    assertThat(singleLineFailureReportOf(result))
            .contains(String.format("classes should call constructor where target is %s",
                    ClassWithConstructor.class.getSimpleName()))
            .containsPattern(callConstructorRegex(
                    ClassCallingWrongConstructor.class,
                    ClassCallingConstructor.class, int.class, Date.class))
            .doesNotMatch(callConstructorRegex(
                    ClassCallingConstructor.class,
                    ClassWithConstructor.class, String.class));
}
 
Example #4
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #5
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("theClass_should_haveSimpleNameStartingWith_rules")
public void theClass_should_haveSimpleNameStartingWith(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    String simpleName = SomeClass.class.getSimpleName();
    String prefix = simpleName.substring(0, simpleName.length() - 1);
    assertThatRules(satisfiedRule, unsatisfiedRule, SomeClass.class, Object.class)
            .haveSuccessfulRuleText("the class %s should have simple name starting with '%s'",
                    SomeClass.class.getName(), prefix)
            .haveFailingRuleText("the class %s should have simple name not starting with '%s'",
                    SomeClass.class.getName(), prefix)
            .containFailureDetail(String.format("simple name of %s starts with '%s' in %s",
                    quote(SomeClass.class.getName()),
                    quote(prefix),
                    locationPattern(SomeClass.class)))
            .doNotContainFailureDetail(quote(Object.class.getName()));
}
 
Example #6
Source File: ClassesShouldConjunctionTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("ANDed_conditions")
public void andShould_ANDs_conditions(ArchRule rule) {
    EvaluationResult result = rule
            .evaluate(importClasses(RightOne.class, RightTwo.class, Wrong.class));

    FailureReport report = result.getFailureReport();
    assertThat(report.toString())
            .contains(String.format(
                    "classes should have fully qualified name '%s' and should have fully qualified name '%s'",
                    RightOne.class.getName(), RightTwo.class.getName()));
    assertThat(report.getDetails()).containsOnly(
            doesntHaveFqnMessage(RightTwo.class, RightOne.class),
            doesntHaveFqnMessage(RightOne.class, RightTwo.class),
            doesntHaveFqnMessage(Wrong.class, RightOne.class),
            doesntHaveFqnMessage(Wrong.class, RightTwo.class));
}
 
Example #7
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("theClass_should_haveNameMatching_rules")
public void theClass_should_haveNameMatching(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    String regex = containsPartOfRegex(SomeClass.class.getSimpleName());

    assertThatRules(satisfiedRule, unsatisfiedRule, SomeClass.class, Object.class)
            .haveSuccessfulRuleText("the class %s should have name matching '%s'",
                    SomeClass.class.getName(), regex)
            .haveFailingRuleText("the class %s should have name not matching '%s'",
                    SomeClass.class.getName(), regex)
            .containFailureDetail(String.format("Class <%s> matches '%s' in %s",
                    quote(SomeClass.class.getName()),
                    quote(regex),
                    locationPattern(SomeClass.class)))
            .doNotContainFailureDetail(quote(regex));
}
 
Example #8
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("theClass_should_haveOnlyFinalFields_rules")
public void theClass_should_haveOnlyFinalFields(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    assertThatRules(satisfiedRule, unsatisfiedRule, ClassWithFinalFields.class, ClassWithNonFinalFields.class)
            .haveSuccessfulRuleText("the class %s should have only final fields",
                    ClassWithFinalFields.class.getName())
            .haveFailingRuleText("the class %s should have only final fields",
                    ClassWithNonFinalFields.class.getName())
            .containFailureDetail(String.format("Field <%s.integerField> is not final in %s",
                    quote(ClassWithNonFinalFields.class.getName()),
                    locationPattern(GivenClassShouldTest.class)))
            .containFailureDetail(String.format("Field <%s.stringField> is not final in %s",
                    quote(ClassWithNonFinalFields.class.getName()),
                    locationPattern(GivenClassShouldTest.class)))
            .doNotContainFailureDetail(quote(ClassWithFinalFields.class.getName()));
}
 
Example #9
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("theClass_should_haveSimpleNameContaining_rules")
public void theClass_should_haveSimpleNameContaining(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    String simpleName = SomeClass.class.getSimpleName();
    String infix = simpleName.substring(1, simpleName.length() - 1);
    assertThatRules(satisfiedRule, unsatisfiedRule, SomeClass.class, Object.class)
            .haveSuccessfulRuleText("the class %s should have simple name containing '%s'",
                    SomeClass.class.getName(), infix)
            .haveFailingRuleText("the class %s should have simple name not containing '%s'",
                    SomeClass.class.getName(), infix)
            .containFailureDetail(String.format("simple name of %s contains '%s' in %s",
                    quote(SomeClass.class.getName()),
                    quote(infix),
                    locationPattern(SomeClass.class)))
            .doNotContainFailureDetail(quote(Object.class.getName()));
}
 
Example #10
Source File: ShouldOnlyByClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void areNotMemberClasses_predicate(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyBeBy.areNotMemberClasses())
            .on(ClassAccessingStaticNestedClass.class, StaticNestedClassBeingAccessed.class,
                    ClassAccessingOtherClass.class, ClassBeingAccessedByOtherClass.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingStaticNestedClass.class, StaticNestedClassBeingAccessed.class);
}
 
Example #11
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("classes_should_only_that_rule_starts")
public void only_areProtected(ClassesThat<ClassesShouldConjunction> classesShouldOnlyThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(classesShouldOnlyThatRuleStart.areProtected())
            .on(ClassAccessingPublicClass.class, ClassAccessingPrivateClass.class,
                    ClassAccessingPackagePrivateClass.class, ClassAccessingProtectedClass.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingPublicClass.class, ClassAccessingPrivateClass.class,
            ClassAccessingPackagePrivateClass.class);
}
 
Example #12
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("classes_should_only_that_rule_starts")
public void only_doNotHaveSimpleName(ClassesThat<ClassesShouldConjunction> classesShouldOnlyThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyThatRuleStart.doNotHaveSimpleName(List.class.getSimpleName()))
            .on(ClassAccessingList.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThat(getOnlyElement(classes)).matches(ClassAccessingList.class);
}
 
Example #13
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void doNotHaveFullyQualifiedName(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.doNotHaveFullyQualifiedName(List.class.getName()))
            .on(ClassAccessingList.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingString.class, ClassAccessingIterable.class);
}
 
Example #14
Source File: GivenClassShouldTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("theClass_should_implement_rules")
public void theClass_should_implement(ArchRule satisfiedRule, ArchRule unsatisfiedRule) {
    assertThatRules(satisfiedRule, unsatisfiedRule, ArrayList.class, Object.class)
            .haveSuccessfulRuleText("the class %s should implement %s",
                    ArrayList.class.getName(), Collection.class.getName())
            .haveFailingRuleText("the class %s should not implement %s",
                    ArrayList.class.getName(), Collection.class.getName())
            .containFailureDetail(String.format("Class <%s> implements %s in %s",
                    quote(ArrayList.class.getName()),
                    quote(Collection.class.getName()),
                    locationPattern(ArrayList.class)))
            .doNotContainFailureDetail(quote(Object.class.getName()));
}
 
Example #15
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("classes_should_only_that_rule_starts")
public void only_areNotInterfaces_predicate(ClassesThat<ClassesShouldConjunction> classesShouldOnlyThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyThatRuleStart.areNotInterfaces())
            .on(ClassAccessingList.class, ClassAccessingString.class,
                    ClassAccessingCollection.class, ClassAccessingSimpleClass.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingList.class, ClassAccessingCollection.class);
}
 
Example #16
Source File: DependencyTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("annotated_members")
public void Dependency_from_member_annotation_member(JavaMember annotatedMember) {
    JavaAnnotation<?> annotation = annotatedMember.getAnnotationOfType(SomeAnnotation.class.getName());
    JavaClass memberType = ((JavaClass) annotation.get("value").get());

    Dependency dependency = Dependency.tryCreateFromAnnotationMember(annotation, memberType).get();
    assertThat(dependency.getOriginClass()).isEqualTo(annotatedMember.getOwner());
    assertThat(dependency.getTargetClass()).isEqualTo(memberType);
    assertThat(dependency.getDescription()).as("description")
            .contains(annotatedMember.getDescription() + " has annotation member of type <" + memberType.getName() + ">");
}
 
Example #17
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void resideInAPackage(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.resideInAPackage("..tngtech.."))
            .on(ClassAccessingPublicClass.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingPublicClass.class);
}
 
Example #18
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("implement_not_satisfied_rules")
public void implement_not_satisfied(ArchRule rule, Class<?> classToCheckAgainst, Class<?> violating) {
    EvaluationResult result = rule.evaluate(importHierarchies(violating));

    assertThat(singleLineFailureReportOf(result))
            .contains(String.format("classes should implement %s", classToCheckAgainst.getName()))
            .containsPattern(String.format("Class <%s> does not implement %s in %s",
                    quote(violating.getName()),
                    quote(classToCheckAgainst.getName()),
                    locationPattern(violating)));
}
 
Example #19
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void areNotAssignableTo_predicate(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.areNotAssignableTo(classWithNameOf(Collection.class)))
            .on(ClassAccessingList.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingString.class, ClassAccessingIterable.class);
}
 
Example #20
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("classes_should_only_that_rule_starts")
public void only_resideInAPackage(ClassesThat<ClassesShouldConjunction> classesShouldOnlyThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyThatRuleStart.resideInAPackage("..tngtech.."))
            .on(ClassAccessingPublicClass.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingString.class, ClassAccessingIterable.class);
}
 
Example #21
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void implement_predicate(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.implement(classWithNameOf(Collection.class)))
            .on(ClassAccessingArrayList.class, ClassAccessingList.class, ClassAccessingIterable.class);

    assertThat(getOnlyElement(classes)).matches(ClassAccessingArrayList.class);
}
 
Example #22
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void implement_type(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.implement(Collection.class))
            .on(ClassAccessingArrayList.class, ClassAccessingList.class, ClassAccessingIterable.class);

    assertThat(getOnlyElement(classes)).matches(ClassAccessingArrayList.class);
}
 
Example #23
Source File: MembersShouldTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("haveNameStartingWith_rules")
public void haveNameStartingWith(ArchRule rule, String prefix, String violatingMember) {
    EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));

    assertThat(singleLineFailureReportOf(result))
            .containsPattern(String.format(".*%s.* name does not start with '%s' in %s",
                    quote(violatingMember),
                    quote(prefix),
                    locationPattern(SimpleFieldAndMethod.class)));
}
 
Example #24
Source File: ShouldOnlyByClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void doNotImplement_predicate(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyBeBy.doNotImplement(classWithNameOf(SomeInterface.class)))
            .on(ClassImplementingSomeInterface.class, ClassBeingAccessedByClassImplementingSomeInterface.class,
                    SimpleClass.class, ClassAccessingSimpleClass.class);

    assertThatClasses(classes).matchInAnyOrder(ClassImplementingSomeInterface.class, ClassBeingAccessedByClassImplementingSomeInterface.class);
}
 
Example #25
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example #26
Source File: ClassesShouldTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #27
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void haveSimpleName(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.haveSimpleName(List.class.getSimpleName()))
            .on(ClassAccessingList.class, ClassAccessingString.class, ClassAccessingIterable.class);

    assertThat(getOnlyElement(classes)).matches(ClassAccessingList.class);
}
 
Example #28
Source File: ShouldClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void areNotInnerClasses_predicate(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            noClassesShouldThatRuleStart.areNotInnerClasses())
            .on(ClassAccessingInnerMemberClass.class, ClassAccessingTopLevelClass.class);

    assertThatClasses(classes).matchInAnyOrder(ClassAccessingTopLevelClass.class);
}
 
Example #29
Source File: ShouldOnlyByClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void areMetaAnnotatedWith_typeName(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyBeBy.areMetaAnnotatedWith(SomeAnnotation.class.getName()))
            .on(ClassBeingAccessedByMetaAnnotatedClass.class, MetaAnnotatedClass.class,
                    ClassBeingAccessedByAnnotatedClass.class, AnnotatedClass.class,
                    SimpleClass.class, ClassAccessingSimpleClass.class,
                    MetaAnnotatedAnnotation.class);

    assertThatClasses(classes).matchInAnyOrder(ClassBeingAccessedByAnnotatedClass.class, AnnotatedClass.class,
            SimpleClass.class, ClassAccessingSimpleClass.class);
}
 
Example #30
Source File: ShouldOnlyByClassesThatTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void areAnnotatedWith_predicate(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
    DescribedPredicate<HasType> hasNamePredicate = GET_RAW_TYPE.is(classWithNameOf(SomeAnnotation.class));
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(
            classesShouldOnlyBeBy.areAnnotatedWith(hasNamePredicate))
            .on(ClassBeingAccessedByAnnotatedClass.class, AnnotatedClass.class,
                    SimpleClass.class, ClassAccessingSimpleClass.class);

    assertThatClasses(classes).matchInAnyOrder(SimpleClass.class, ClassAccessingSimpleClass.class);
}