-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for JUnit5DescribedPredicates
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/test/java/com/enofex/taikai/test/JUnit5DescribedPredicatesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.enofex.taikai.test; | ||
|
||
import static com.enofex.taikai.test.JUnit5DescribedPredicates.ANNOTATION_PARAMETRIZED_TEST; | ||
import static com.enofex.taikai.test.JUnit5DescribedPredicates.ANNOTATION_TEST; | ||
import static com.enofex.taikai.test.JUnit5DescribedPredicates.annotatedWithTestOrParameterizedTest; | ||
import static com.tngtech.archunit.lang.conditions.ArchConditions.beAnnotatedWith; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
import com.tngtech.archunit.lang.conditions.ArchConditions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EmptySource; | ||
|
||
class JUnit5DescribedPredicatesTest { | ||
|
||
@Test | ||
void shouldIdentifyClassesAnnotatedWithTestOrParameterizedTest() { | ||
JavaClasses importedClasses = new ClassFileImporter().importClasses( | ||
TestExample.class, ParameterizedTestExample.class); | ||
|
||
ArchRule rule = methods().that(annotatedWithTestOrParameterizedTest(false)) | ||
.should(beAnnotatedWith(ANNOTATION_TEST) | ||
.or(beAnnotatedWith(ANNOTATION_PARAMETRIZED_TEST))); | ||
|
||
rule.check(importedClasses); | ||
} | ||
|
||
@Test | ||
void shouldIdentifyClassesMetaAnnotatedWithTestOrParameterizedTest() { | ||
JavaClasses importedClasses = new ClassFileImporter().importClasses( | ||
MetaTestExample.class, MetaParameterizedTestExample.class); | ||
|
||
ArchRule rule = methods().that(annotatedWithTestOrParameterizedTest(true)) | ||
.should(ArchConditions.beMetaAnnotatedWith(ANNOTATION_TEST) | ||
.or(ArchConditions.beMetaAnnotatedWith(ANNOTATION_PARAMETRIZED_TEST))); | ||
|
||
rule.check(importedClasses); | ||
} | ||
|
||
private static final class TestExample { | ||
|
||
@Test | ||
void testMethod() { | ||
} | ||
} | ||
|
||
private static final class ParameterizedTestExample { | ||
|
||
@ParameterizedTest | ||
@EmptySource | ||
void parameterizedTestMethod(String empty) { | ||
} | ||
} | ||
|
||
private static class MetaTestExample { | ||
|
||
@TestAnnotation | ||
void metaTestMethod() { | ||
} | ||
} | ||
|
||
private static final class MetaParameterizedTestExample { | ||
|
||
@ParameterizedTestAnnotation | ||
@EmptySource | ||
void metaParameterizedTestMethod(String empty) { | ||
} | ||
} | ||
|
||
@Test | ||
private @interface TestAnnotation { | ||
} | ||
|
||
@ParameterizedTest | ||
private @interface ParameterizedTestAnnotation { | ||
} | ||
} |