-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from uhafner/arch-unit-rule-test
Add tests that verify some ArchUnit rules
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.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,51 @@ | ||
package edu.hm.hafner.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
/** | ||
* Verifies the architecture rules in {@link ArchitectureRules}. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
class ArchitectureRulesTest { | ||
@Test | ||
void shouldVerifyNoPublicTestClassesRule() { | ||
JavaClasses violatedClasses = importClasses(NoPublicTestElementsViolatedTest.class); | ||
assertThatExceptionOfType(AssertionError.class).isThrownBy( | ||
() -> ArchitectureRules.NO_PUBLIC_TEST_CLASSES.check(violatedClasses)); | ||
JavaClasses passedClasses = new ClassFileImporter().importClasses(NoPublicTestElementsPassedTest.class); | ||
assertThatNoException().isThrownBy( | ||
() -> ArchitectureRules.NO_PUBLIC_TEST_CLASSES.check(passedClasses)); | ||
} | ||
|
||
@Test | ||
void shouldVerifyNoPublicTestMethodsRule() { | ||
JavaClasses violatedClasses = importClasses(NoPublicTestElementsViolatedTest.class); | ||
assertThatExceptionOfType(AssertionError.class).isThrownBy( | ||
() -> ArchitectureRules.ONLY_PACKAGE_PRIVATE_TEST_METHODS.check(violatedClasses)); | ||
JavaClasses passedClasses = new ClassFileImporter().importClasses(NoPublicTestElementsPassedTest.class); | ||
assertThatNoException().isThrownBy( | ||
() -> ArchitectureRules.ONLY_PACKAGE_PRIVATE_TEST_METHODS.check(passedClasses)); | ||
} | ||
|
||
private JavaClasses importClasses(final Class<?>... classes) { | ||
return new ClassFileImporter().importClasses(classes); | ||
} | ||
|
||
public static class NoPublicTestElementsViolatedTest { | ||
@Test | ||
public void shouldFail() { | ||
} | ||
} | ||
|
||
static class NoPublicTestElementsPassedTest { | ||
@Test | ||
void shouldPass() { | ||
} | ||
} | ||
} |
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