Unit test your boilerplate without more boilerplate
Boilerplate verifiers can be used in Java unit tests to verify whether the builder, toString, getters/setters are correctly implemented.
Inspired by the awesome EqualsVerifier. This is also the reason why equals and hashcode verifiers are notably absent.
- Implement BuilderVerifier
Support for POJOSSupport for inheritance in the classes to buildVerify that all attributes are being build.Support for inheritance in the builder classes themselvesVerify that no attribute can be set after build.Verify the builder constructor is not accessible from the outside.Support for more scenarios using settings1.Support for attribute blacklist2.Support for builder class method blacklist3.Force don't use getter's to verify attribute values4.Support for custom value factories5.Support for not buildable Super classes6.Support for prefixed methods on builder class (i.e. "withAge()", "withName()", etc)7.Support for ignoring verification of attribute accessibility.- Implement ToStringVerifier
Support for POJOSSupport for graphs (deep toString)Support for loops in graphsSupport for inheritance (also uses toString of super class)- Support for more scenarios using settings
1. Configure the key-value template
2.
Configure graph blacklist using the path.3. Configure inheritance behavior. 4. Configure shallow toString behavior. - Implement GetterSetterVerifier
// Book.java
public class Book {
private final Person author;
private final String title;
Book(Person author, String title) {
this.author = author;
this.title = title;
}
public static BookBuilder builder() {
return new BookBuilder();
}
public static class BookBuilder {
// ... boilerplate ...
}
}
// BookTest.java
@Test
public void verifyBuilder() {
BuilderVerifier.forClass(Book.class).verify();
}
Highly configurable:
public void verifyBuilderWithAllPossibleSettings() {
BuilderVerifier.forClass(Book.class)
.allAttributesShouldBeBuildExcept("author")
.allMethodsOnBuilderClassShouldBeUsedExcept("copyTo")
.usingBuilderMethod("buildBook")
.withoutBuildingSuperClasses()
.withoutUsingGettersForVerification()
.withoutVerifyingAttributeAccessibility()
.withPrefixForAllMethodsOnBuilder("with")
.withValueFactories(new MyCustomValueFactory())
.verify();
}