OpenPojo
![Maven Central](https://camo.githubusercontent.com/be2207dccfa48c7bea6c80ee3b4c962850cd580925c444e22915280046108be8/68747470733a2f2f6d6176656e2d6261646765732e6865726f6b756170702e636f6d2f6d6176656e2d63656e7472616c2f636f6d2e6f70656e706f6a6f2f6f70656e706f6a6f2f62616467652e737667)
POJO Testing & Identity Management Made Trivial
Maven Group Plugin | Latest Version |
---|---|
com.openpojo.openpojo | 0.9.1 |
Testing Example
public class PojoTest {
// Configured for expectation, so we know when a class gets added or removed.
private static final int EXPECTED_CLASS_COUNT = 1;
// The package to test
private static final String POJO_PACKAGE = "com.openpojo.sample";
@Test
public void ensureExpectedPojoCount() {
List <PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(POJO_PACKAGE,
new FilterPackageInfo());
Affirm.affirmEquals("Classes added / removed?", EXPECTED_CLASS_COUNT, pojoClasses.size());
}
@Test
public void testPojoStructureAndBehavior() {
Validator validator = ValidatorBuilder.create()
// Add Rules to validate structure for POJO_PACKAGE
// See com.openpojo.validation.rule.impl for more ...
.with(new GetterMustExistRule())
.with(new SetterMustExistRule())
// Add Testers to validate behaviour for POJO_PACKAGE
// See com.openpojo.validation.test.impl for more ...
.with(new SetterTester())
.with(new GetterTester())
.build();
validator.validate(POJO_PACKAGE, new FilterPackageInfo());
}
}
Identity Management Example
public class Person {
@BusinessKey(caseSensitive = false) //Configure your field(s)
private String lastName;
@Override
public boolean equals(Object obj) {
return BusinessIdentity.areEqual(this, obj);
}
@Override
public int hashCode() {
return BusinessIdentity.getHashCode(this);
}
@Override
public String toString() {
return BusinessIdentity.toString(this);
}
}
For more examples and the tutorials see the Wiki