Skip to content

Java is a language filled with boilderplate code constructs. ToString implementations, Builders, Getters and Setters. This repo contains verifiers for this boilerplate code. Inspired by EqualsVerifier (https://github.com/jqno/equalsverifier)

nicojs/boilerplate-verifiers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Boilerplate verifiers for Java

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.

Work in progress:

  1. Implement BuilderVerifier
  2. Support for POJOS
  3. Support for inheritance in the classes to build
  4. Verify that all attributes are being build.
  5. Support for inheritance in the builder classes themselves
  6. Verify that no attribute can be set after build.
  7. Verify the builder constructor is not accessible from the outside.
  8. Support for more scenarios using settings 1. Support for attribute blacklist 2. Support for builder class method blacklist 3. Force don't use getter's to verify attribute values 4. Support for custom value factories 5. Support for not buildable Super classes 6. Support for prefixed methods on builder class (i.e. "withAge()", "withName()", etc) 7. Support for ignoring verification of attribute accessibility.
  9. Implement ToStringVerifier
  10. Support for POJOS
  11. Support for graphs (deep toString)
  12. Support for loops in graphs
  13. Support for inheritance (also uses toString of super class)
  14. 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.
  15. Implement GetterSetterVerifier

Builder

    // 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();
    }

About

Java is a language filled with boilderplate code constructs. ToString implementations, Builders, Getters and Setters. This repo contains verifiers for this boilerplate code. Inspired by EqualsVerifier (https://github.com/jqno/equalsverifier)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages