How To Use Jboss Forge Assertj Assertions Generator

This time i want to present the JBoss-Forge AssertJ Addon which is brand new and basically does the maven integration of the AssertJ Assertions Generator

If you are not familiar with either JBoss Forge or AssertJ you really should have a look on that because it will speed up your development.

Installation

Before you can use this addon you have to install it first.

1 forge -i org.assertj.forge:assertj-forge-addon

Minimal Setup

The minimal setup for AssertJ Assertions Generator requires either a package or a class name for which the generator should be used. To do so you need to create a project first.

1 [github]$ project-new --named petstore
2 ***SUCCESS*** Project named 'petstore' has been created.
3 [petstore]$ assertj-assertions-generator-setup --packages org.petshop.model
4 ***SUCCESS*** Command 'assertj-setup' successfully executed!

The assertj-assertions-generator-setup command basically:

The resulting pom.xml looks like this:

 1 [petstore]$ cat pom.xml
 2 <?xml version="1.0" encoding="UTF-8"?>
 3 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 5   <modelVersion>4.0.0</modelVersion>
 6   <groupId>org.petstore</groupId>
 7   <artifactId>petstore</artifactId>
 8   <version>1.0.0-SNAPSHOT</version>
 9   <packaging>war</packaging>
10   <properties>
11     <version.assertj>2.0.0</version.assertj>
12     <version.assertj-generator>1.6.0</version.assertj-generator>
13     <maven.compiler.source>1.7</maven.compiler.source>
14     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15     <maven.compiler.target>1.7</maven.compiler.target>
16   </properties>
17   <dependencies>
18     <dependency>
19       <groupId>org.assertj</groupId>
20       <artifactId>assertj-core</artifactId>
21       <version>${version.assertj}</version>
22       <scope>test</scope>
23     </dependency>
24   </dependencies>
25   <build>
26     <finalName>petstore</finalName>
27     <plugins>
28       <plugin>
29         <artifactId>maven-war-plugin</artifactId>
30         <version>2.4</version>
31         <configuration>
32           <failOnMissingWebXml>false</failOnMissingWebXml>
33         </configuration>
34       </plugin>
35       <plugin>
36         <groupId>org.assertj</groupId>
37         <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
38         <version>${version.assertj-generator}</version>
39         <executions>
40           <execution>
41             <goals>
42               <goal>generate-assertions</goal>
43             </goals>
44           </execution>
45         </executions>
46         <configuration>
47           <packages>
48             <param>org.petshop.model</param>
49           </packages>
50         </configuration>
51       </plugin>
52     </plugins>
53   </build>
54 </project>

The following bash snippet shows all parameters of that command which are described either in the man page of assertj-assertions-generator-setup or AssertJ Assertions Generator.

1 [petstore]$ assertj-assertions-generator-setup 
2 --version                         --excludes                        --notGenerateAssertions
3 --notGenerateJUnitSoftAssertions  --packages                        --includes
4 --notGenerateBddAssertions        --entryPointClassPackage          --classes
5 --notHierarchical                 --notGenerateSoftAssertions       --targetDir

AFAIK there is now faster way to use your domain model assertions in your tests then this.

The code for that can be found on my github repositoy: https://github.com/AlexBischof/assertj-forge-addon