-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule checking test and implementation class are in same package #908
This will add the library rule `GeneralCodingRules.testClassesShouldResideInTheSamePackageAsImplementation(..)` which will test that implementation and test class reside in the same package. The rule can e.g. detect mismatches like `com.myapp.correct.SomeClass` and `com.myapp.wrong.SomeClassTest`. Resolves: #475
- Loading branch information
Showing
9 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
archunit/src/test/java/com/tngtech/archunit/library/GeneralCodingRulesTest.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,44 @@ | ||
package com.tngtech.archunit.library; | ||
|
||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.library.testclasses.packages.correct.ImplementationClassWithCorrectPackage; | ||
import com.tngtech.archunit.library.testclasses.packages.incorrect.ImplementationClassWithWrongTestClassPackage; | ||
import com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir.ImplementationClassWithWrongTestClassPackageTest; | ||
import com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir.ImplementationClassWithWrongTestClassPackageTestingScenario; | ||
import org.junit.Test; | ||
|
||
import static com.tngtech.archunit.library.GeneralCodingRules.testClassesShouldResideInTheSamePackageAsImplementation; | ||
import static com.tngtech.archunit.testutil.Assertions.assertThatRule; | ||
|
||
public class GeneralCodingRulesTest { | ||
|
||
@Test | ||
public void test_class_in_same_package_should_fail_when_test_class_reside_in_different_package_as_implementation() { | ||
assertThatRule(testClassesShouldResideInTheSamePackageAsImplementation()) | ||
.checking(new ClassFileImporter().importPackagesOf(ImplementationClassWithWrongTestClassPackage.class)) | ||
.hasOnlyOneViolationWithStandardPattern(ImplementationClassWithWrongTestClassPackageTest.class, | ||
"does not reside in same package as implementation class <" + ImplementationClassWithWrongTestClassPackage.class.getName() + ">"); | ||
} | ||
|
||
@Test | ||
public void test_class_in_same_package_should_fail_when_test_class_reside_in_different_package_as_implementation_with_custom_suffix() { | ||
assertThatRule(testClassesShouldResideInTheSamePackageAsImplementation("TestingScenario")) | ||
.checking(new ClassFileImporter().importPackagesOf(ImplementationClassWithWrongTestClassPackage.class)) | ||
.hasOnlyOneViolationWithStandardPattern(ImplementationClassWithWrongTestClassPackageTestingScenario.class, | ||
"does not reside in same package as implementation class <" + ImplementationClassWithWrongTestClassPackage.class.getName() + ">"); | ||
} | ||
|
||
@Test | ||
public void test_class_in_same_package_should_pass_when_test_class_and_implementation_class_reside_in_the_same_package() { | ||
assertThatRule(testClassesShouldResideInTheSamePackageAsImplementation()) | ||
.checking(new ClassFileImporter().importPackagesOf(ImplementationClassWithCorrectPackage.class)) | ||
.hasNoViolation(); | ||
} | ||
|
||
@Test | ||
public void test_class_in_same_package_should_pass_when_test_class_and_implementation_class_reside_in_the_same_package_with_custom_suffix() { | ||
assertThatRule(testClassesShouldResideInTheSamePackageAsImplementation("TestingScenario")) | ||
.checking(new ClassFileImporter().importPackagesOf(ImplementationClassWithCorrectPackage.class)) | ||
.hasNoViolation(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../archunit/library/testclasses/packages/correct/ImplementationClassWithCorrectPackage.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.correct; | ||
|
||
public class ImplementationClassWithCorrectPackage { | ||
} |
4 changes: 4 additions & 0 deletions
4
...hunit/library/testclasses/packages/correct/ImplementationClassWithCorrectPackageTest.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.correct; | ||
|
||
public class ImplementationClassWithCorrectPackageTest { | ||
} |
4 changes: 4 additions & 0 deletions
4
...ry/testclasses/packages/correct/ImplementationClassWithCorrectPackageTestingScenario.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.correct; | ||
|
||
public class ImplementationClassWithCorrectPackageTestingScenario { | ||
} |
4 changes: 4 additions & 0 deletions
4
.../library/testclasses/packages/incorrect/ImplementationClassWithWrongTestClassPackage.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.incorrect; | ||
|
||
public class ImplementationClassWithWrongTestClassPackage { | ||
} |
4 changes: 4 additions & 0 deletions
4
...sses/packages/incorrect/wrongsubdir/ImplementationClassWithWrongTestClassPackageTest.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir; | ||
|
||
public class ImplementationClassWithWrongTestClassPackageTest { | ||
} |
4 changes: 4 additions & 0 deletions
4
...es/incorrect/wrongsubdir/ImplementationClassWithWrongTestClassPackageTestingScenario.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,4 @@ | ||
package com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir; | ||
|
||
public class ImplementationClassWithWrongTestClassPackageTestingScenario { | ||
} |
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