Set of custom ArchUnit rules to ensure Elegant Objects principles respect.
eorules helps you design and craft code that respect strong object-oriented programming paradigm.
- Check that classes are abstract or final
- Check that classes have no static methods
- Check that classes have no getters and no setters
- Check that classes have no private methods
- Check that fields are final
- Check that public methods are defined in interface
Add the dependency to your project:
<dependency>
<groupId>com.github.roroche</groupId>
<artifactId>eorules</artifactId>
<version>${latest.version}</version>
<scope>test</scope>
</dependency>class ArchitectureTest {
private final JavaClasses classes = new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
.importPackages("com.example");
@Test
void checksClassesAreAbstractOrFinal() {
new ClassesAreAbstractOrFinalRule().check(this.classes);
}
@Test
void checksThereAreNoStaticMethods() {
new ClassesShouldHaveNoStaticMethodsRule().check(this.classes);
}
@Test
void checksClassesDoNotHaveGettersOrSetters() {
new ClassesShouldNotHaveGettersOrSettersRule().check(this.classes);
}
@Test
void checksClassesDoNotHavePrivateMethods() {
new ClassesShouldNotHavePrivateMethodsRule().check(this.classes);
}
@Test
void checksFieldsAreFinal() {
new FieldsShouldBeFinalRule().check(this.classes);
}
@Test
void checksPublicMethodsAreDeclaredInInterfaces() {
new PublicMethodsDeclaredInInterfacesRule().check(this.classes);
}
}To bypass the checks, you can annotate your class with @ExcludeFromArchUnit.
Contributions are welcome!
If you'd like to report a bug, suggest a feature, or submit a pull request, please read our 👉 Contributing Guide
It contains everything you need to know about:
- Development setup
- Coding standards
- Commit conventions
- Pull request process
- Quality requirements
Thank you for helping improve eorules 🚀
Distributed under the MIT License. See LICENSE for more information.