Skip to content

Tutorial 2. Simple Bulk Validation, Single Package

Osman Shoukry edited this page Dec 16, 2015 · 6 revisions

All my Pojos are in package com.mycompany.data.

Suppose that now instead of writing one test per class you'd like to validate that all your POJO's that are used for data transfer in and out of the database or some other system are behaving correctly.

public class SinglePackageTest {
  // The package to be tested
  private String packageName = "com.mycompany.data";

  @Test
  public void validate() {
    Validator validator = ValidatorBuilder.create()
                            .with(new SetterMustExistRule(),
                                  new GetterMustExistRule())
                            .with(new SetterTester(),
                                  new GetterTester())
                            .build();
    validator.validate(packageName);
  }
}