This is a Java libraries with some utilities (mainly transformers, predicates and conditions) to empower your ArchUnit test. ArchUnit is a free, simple and extensible library for checking the architecture of a Java code.
This library depends on JUnit 5. If you are using the previous version, please upgrade.
In general, a rule is applied to JavaClasses that can be transformed to custom objects, and then filtered by predicates and checked against given conditions.
To get you started you can simply clone the arch-utils
repository and install the dependencies.
You need git to clone the arch-utils
repository.
You will need Java™ SE Development Kit 8 and Maven.
Clone the arch-utils
repository using git:
git clone https://github.com/systelab/arch-utils.git
cd arch-utils
In order to install the dependencies, you must run:
mvn clean install
In order to release a new version:
Step 1. Update the version in your pom.xml file. For example:
<version>1.1.0</version>
Step 2. Commit and push in the master branch, and generate a new Release by pressing the button "Draft new release".
In the example use v1.1.0 as the Tag version, and 1.1.0 as the release title.
Step 3. Head to https://jitpack.io and look up "systelab/arch-utils". Choose the new version and press the button "Get it". Check the log to verify that everything is fine.
In order to use the library, you should add the dependency to your project.
In order to use the library, you should:
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.systelab:arch-utils:v1.1.0'
}
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.systelab</groupId>
<artifactId>arch-utils</artifactId>
<version>v1.1.0</version>
</dependency>
ClassesTransformer define how JavaClasses are to be transformed to the desired rule input. The following transformers are provided:
- constructors()
- fields()
- methods()
For example:
@ArchTest
static ArchRule allPublicMethodsInRestControllersShouldReturnResponseEntity =
all(methods())
.that(inClassesAnnotatedWith(MyAnnotation.class)).and(arePublic())
.should(returnType(String.class))
.because("we want to have String in methods of classes annotated with @MyAnnotation");
- haveAllFieldsPublic()
- notHaveTheField(String fieldname)
- inClassesAnnotatedWith(Class className)
- beAnnotated(Class className)
- returnType(Class className)