Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that tests are package private when using JUnit 5 #371

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions etc/pmd-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<exclude name="UnusedImports"/>
<exclude name="GuardLogStatement"/>
<exclude name="AccessorMethodGeneration"/>
<exclude name="JUnit5TestShouldBePackagePrivate"/>
<exclude name="UnusedPrivateMethod"/>
</rule>
<rule ref="category/java/codestyle.xml">
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/edu/hm/hafner/util/ArchitectureRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ private ArchitectureRules() {
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.should().bePublic();

/** Junit 5 test methods should not be public. */
public static final ArchRule NO_PUBLIC_TEST_METHODS =
/** Junit 5 test methods should be package private. */
public static final ArchRule ONLY_PACKAGE_PRIVATE_TEST_METHODS =
methods().that().areAnnotatedWith(Test.class)
.or().areAnnotatedWith(ParameterizedTest.class)
.and().areDeclaredInClassesThat()
.haveSimpleNameEndingWith("Test")
.should().notBePublic();
.should().bePackagePrivate();

/** ArchUnit tests should not be public. */
public static final ArchRule NO_PUBLIC_ARCHITECTURE_TESTS =
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/util/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArchitectureTest {
static final ArchRule NO_PUBLIC_TEST_CLASSES = ArchitectureRules.NO_PUBLIC_TEST_CLASSES;

@ArchTest
static final ArchRule NO_PUBLIC_TEST_METHODS = ArchitectureRules.NO_PUBLIC_TEST_METHODS;
static final ArchRule ONLY_PACKAGE_PRIVATE_TEST_METHODS = ArchitectureRules.ONLY_PACKAGE_PRIVATE_TEST_METHODS;

@ArchTest
static final ArchRule NO_PUBLIC_ARCHITECTURE_TESTS = ArchitectureRules.NO_PUBLIC_ARCHITECTURE_TESTS;
Expand Down