GithubHelp home page GithubHelp logo

arch-utils's Introduction

ArchUnit utilities

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.

Image

Getting Started

To get you started you can simply clone the arch-utils repository and install the dependencies.

Prerequisites

You need git to clone the arch-utils repository.

You will need Java™ SE Development Kit 8 and Maven.

Clone

Clone the arch-utils repository using git:

git clone https://github.com/systelab/arch-utils.git
cd arch-utils

Install Dependencies

In order to install the dependencies, you must run:

mvn clean install

Release

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.

Using the library

In order to use the library, you should add the dependency to your project.

Gradle

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'
}

Maven

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>

Custom Objects

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");

Classes

Conditions

  • haveAllFieldsPublic()
  • notHaveTheField(String fieldname)

Methods

Predicates

  • inClassesAnnotatedWith(Class className)

Conditions

  • beAnnotated(Class className)
  • returnType(Class className)

arch-utils's People

Contributors

alfonsserra avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.