Test pojos using maven plugin instead of boilerplate. Just as lombok can reduce writing bolierplate for POJOs, this plugin can reduce the unit tests you need to write.
This plugin is designed to used with jacoco maven plugin.
To include testpojo-maven-plugin in your maven build, use the following fragment in your pom.
<build>
<plugins>
<plugin>
<groupId>org.honton.chas</groupId>
<artifactId>testpojo-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<id>test-pojos</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
testpojo-maven-plugin provides a single 'test' goal which defaults to running in the test phase.
- constructor
- equals
- hashCode
- getters and setters
- lombok builder
- Jackson marshalling and demarshalling
Using Reflections, all code in the ${build.outputDirectory} is introspected. Any class with method implementations for both equals and hashCode and has a public constructor is considered a bean.
- Construct bean with public constructor having least number of arguments.
- Execute toString() and make sure no exceptions occur.
- Use Jackson to marshall to Map and back to new instance of POJO.
- Check copy.equals(original)
- Check copy.hashCode() == original.hashCode()
- Use Jackson to marshall to json string and back to new instance of POJO.
- Check copy.equals(original)
- Check copy.hashCode() == original.hashCode()
- Create variants by executing each setter with value. If the Bean has a Lombok @Builder, the builder will be used to populate the bean instead of setters.
- Check !variant.equals(original)
- Execute steps 2-4 above