Skip to content

Commit

Permalink
Rename naming packagesShouldMatch rule to java classesShouldResideInP…
Browse files Browse the repository at this point in the history
…ackage rule
  • Loading branch information
mnhock authored and mnhock committed Sep 23, 2024
1 parent 4f9db44 commit 4656059
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
14 changes: 12 additions & 2 deletions docs/USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ The default mode is `WITHOUT_TESTS`, which excludes test classes from the import
|----------|--------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| General | `classesShouldImplementHashCodeAndEquals` | Classes should implement `hashCode` and `equals` together. |
| General | `classesShouldResideInPackage` | Classes matching specific naming patterns should reside in a specified package. |
| General | `classesShouldResideInPackage` | Classes should reside in a specified package. (e.g., `com.company.project..`). |
| General | `classesAnnotatedWithShouldResideInPackage` | Classes annotated with a specific annotation should reside in a specified package. |
| General | `classesShouldResideOutsidePackage` | Classes matching specific naming patterns should reside outside a specified package. |
| General | `classesShouldBeAnnotatedWith` | Classes matching specific naming patterns should be annotated with a specified annotation. |
Expand All @@ -127,7 +128,6 @@ The default mode is `WITHOUT_TESTS`, which excludes test classes from the import
| General | `serialVersionUIDShouldBeStaticFinalLong` | Fields named `serialVersionUID` should be declared as `static final long`. |
| Imports | `shouldHaveNoCycles` | No cyclic dependencies in imports. |
| Imports | `shouldNotImport` | Disallow specific imports (e.g., `..shaded..`). |
| Naming | `packagesShouldMatch` | Packages should match the specified regex pattern (e.g., `com.company.project..`). |
| Naming | `classesShouldNotMatch` | Classes should not match specific naming patterns (e.g., `.*Impl`). |
| Naming | `classesAnnotatedWithShouldMatch` | Classes annotated with a specific annotation should match specific naming patterns. |
| Naming | `methodsShouldNotMatch` | Methods should not match specific naming patterns. |
Expand Down Expand Up @@ -228,6 +228,17 @@ Taikai.builder()
.check();
```

- **Classes Should Reside in Specified Package**: Ensure that classes reside in the specified package.

```java
Taikai.builder()
.namespace("com.company.project")
.java(java -> java
.classesShouldResideInPackage("com.company.project.."))
.build()
.check();
```

- **Classes Annotated with Specified Annotation Should Reside in Specified Package**: Ensure that classes annotated with a specific annotation reside in the specified package.

```java
Expand Down Expand Up @@ -403,7 +414,6 @@ Taikai.builder()
.namespace("com.company.project")
.java(java -> java
.naming(naming -> naming
.packagesShouldMatch("com.company.project..")
.classesShouldNotMatch(".*Impl")
.classesAnnotatedWithShouldMatch(Annotation.class, "coolClass")
.classesAnnotatedWithShouldMatch("com.company.project.Annotation", "coolClass")
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/enofex/taikai/java/JavaConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public JavaConfigurer noUsageOfDeprecatedAPIs(Configuration configuration) {
return addRule(TaikaiRule.of(classes().should(notUseDeprecatedAPIs()), configuration));
}

public JavaConfigurer classesShouldResideInPackage(String packageIdentifier) {
return classesShouldResideInPackage(packageIdentifier, defaultConfiguration());
}

public JavaConfigurer classesShouldResideInPackage(String packageIdentifier,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.should().resideInAPackage(packageIdentifier)
.as("Package names should match %s".formatted(packageIdentifier)),
configuration));
}

public JavaConfigurer classesShouldResideInPackage(String regex, String packageIdentifier) {
return classesShouldResideInPackage(regex, packageIdentifier, defaultConfiguration());
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/enofex/taikai/java/NamingConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ public class NamingConfigurer extends AbstractConfigurer {
super(configurerContext);
}

public NamingConfigurer packagesShouldMatch(String packageIdentifier) {
return packagesShouldMatch(packageIdentifier, defaultConfiguration());
}

public NamingConfigurer packagesShouldMatch(String packageIdentifier,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.should().resideInAPackage(packageIdentifier)
.as("Package names should match %s".formatted(packageIdentifier)),
configuration));
}

public NamingConfigurer classesShouldNotMatch(String regex) {
return classesShouldNotMatch(regex, defaultConfiguration());
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/enofex/taikai/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void shouldFulfilConstrains() {
.methodsShouldNotDeclareGenericExceptions()
.fieldsShouldNotBePublic()
.serialVersionUIDFieldsShouldBeStaticFinalLong()
.classesShouldResideInPackage("com.enofex.taikai..")
.imports(imports -> imports
.shouldHaveNoCycles()
.shouldNotImport("..shaded..")
.shouldNotImport("..lombok..")
.shouldNotImport("org.junit.."))
.naming(naming -> naming
.packagesShouldMatch("com.enofex.taikai..")
.classesShouldNotMatch(".*Impl")
.interfacesShouldNotHavePrefixI()
.constantsShouldFollowConventions()))
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/enofex/taikai/Usage.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public static void main(String[] args) {
.finalClassesShouldNotHaveProtectedMembers()
.utilityClassesShouldBeFinalAndHavePrivateConstructor()
.serialVersionUIDFieldsShouldBeStaticFinalLong()
.classesShouldResideInPackage("com.enofex.taikai..")
.imports(imports -> imports
.shouldHaveNoCycles()
.shouldNotImport("..shaded..")
.shouldNotImport("..lombok..")
.shouldNotImport("org.junit..")
.shouldNotImport(".*ImportsConfigurer", "com.enofex.taikai.TaikaiException"))
.naming(naming -> naming
.packagesShouldMatch("com.enofex.taikai..")
.classesShouldNotMatch(".*Impl")
.methodsShouldNotMatch("foo")
.fieldsShouldNotMatch("bar")
Expand Down

0 comments on commit 4656059

Please sign in to comment.