GitXplorerGitXplorer
l

testpojo-maven-plugin

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
8a18a58f9659f8c6c57774690157d65c3380c4b9

fix #4, support fluent setters

cchonton committed 7 years ago
Unverified
da1ad4bb53da9f2582f43125d4d1025422220649

added tests; better diagnostics; support private classes

cchonton committed 8 years ago
Unverified
18637603a6dcadc4c3c2d3de4fb5e05d8edfdedb

release version 0.0.5

cchonton committed 9 years ago
Unverified
963fecb73e0567fad17217d33aeb63a5eb9e2150

add joda support

cchonton-elementum committed 9 years ago
Unverified
4f058d99551352164823c901f560191370da4a77

Merge pull request #1 from chonton-elementum/master

cchonton committed 9 years ago
Unverified
a7d33063143dd3ec7374d747ac842ebd6926ac70

detect cycles, better standard and variant args

cchonton-elementum committed 9 years ago

README

The README file for this repository.

testpojo-maven-plugin

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.

Requirements

This plugin is designed to used with jacoco maven plugin.

Maven Configuration

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.

What gets tested

How testpojo-maven-plugin works

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.

Bean test consists of the following steps.

  1. Construct bean with public constructor having least number of arguments.
  2. Execute toString() and make sure no exceptions occur.
  3. Use Jackson to marshall to Map and back to new instance of POJO.
  • Check copy.equals(original)
  • Check copy.hashCode() == original.hashCode()
  1. Use Jackson to marshall to json string and back to new instance of POJO.
  • Check copy.equals(original)
  • Check copy.hashCode() == original.hashCode()
  1. 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