OpenPojo / openpojo

POJO Testing & Identity Management Made Trivial
http://openpojo.com
Apache License 2.0
156 stars 40 forks source link

Include only selected pojo from a package , while validating #126

Closed mona2702 closed 5 years ago

mona2702 commented 5 years ago

Hi team, Can you please help , how to include selected pojo from a package and use directly with the validate method. how to provide directly the class in the param.

oshoukry commented 5 years ago

If you want a single Pojo to be validated, you can do the following:

  @Test
  public void someTestMethod() {
    Validator validator = ValidatorBuilder.create()
                            // Add Rules see com.openpojo.validation.rule.impl for more ...
                            .with(new SomeRule())
                            // Add Testers see com.openpojo.validation.test.impl for more ...
                            .with(new someTester())
                            .build();

    PojoClass classToValidate = PojoClassFactory.getPojoClass(com.package.ClassToValidate);
    validator.validate(classToValidate);
  }

Another way is to use PojoClassFactory.getPojoClasses("package name", "filter to select just what you need");