Skip to content

hazendaz/javabean-tester

 
 

Repository files navigation

javabean-tester

Java CI Coverage Status Renovate enabled Maven central Project Stats Apache 2

Latest Release

You can download source binaries from our releases page and release binaries from Maven central

Alternatively you can pull it using Maven:

<dependency>
  <groupId>com.github.hazendaz</groupId>
  <artifactId>javabean-tester</artifactId>
  <version>2.6.3</version>
  <scope>test</scope>
</dependency>

Or using Gradle:

testImplementation 'com.github.hazendaz:javabean-tester:2.6.3'

Information for other build frameworks can be found here.

Requires java 11+

Sites

Javabean Tester is a reflection based library for testing java beans. Effectively test constructors, clear, getters/setters, hashcode, toString, equals, and serializable are correct.

Left Codebox

Original maintainer codebox only intended for this project to be a simple class that users would make additional changes to. Over time, this copy has evolved into a full project and now is the primary project going forwards. Issues has been opened up for use and pull requests are gladly appreciated. Original maintainer has now made his version gradle enabled build but it still lacks additional features found here.

Documentation Status

Actively accepting pull requests for documentation of this library. Focus will only be on new builder pattern. Vast majority of examples exist in the test package.

Example Usage

JavaBeanTester.builder(Test.class, Extension.class).checkEquals().checkSerializable()
        .loadData().skipStrictSerializable().skip("FieldToSkip", "AnotherFieldToSkip").test();
JavaBeanTester.builder(Test.class).loadData().testEquals(instance1, instance2);
JavaBeanTester.builder(Test.class).testPrivateConstructor();

Check Equals will perform equality checks. This applies when hashcode, toString, and equals/canEqual are setup.

Check Serializable will perform a serialization check. This ensures that just because a class is marked as serializable that it really is serializable including children.

Load Data will load underlying data as best possible for basic java types.

Skip Strict Serializable will not perform a serialization check as this is only valid for POJOs currently.

Skip will skip all included elements from underlying getter/setter checks.