我正在使用 OpenPojo 对我的 JPA 实体进行自动化测试。我在引用其他实体的实体时遇到问题。
例子:
public class Person {
@BusinessKey
private Integer id;
...getters/setters
@Override
public boolean equals(Object obj) {
return BusinessIdentity.areEqual(this, obj);
}
@Override
public int hashCode() {
return BusinessIdentity.getHashCode(this);
}
}
public class Employee {
@BusinessKey
private Integer id;
private Person person;
...getters/setters
@Override
public boolean equals(Object obj) {
return BusinessIdentity.areEqual(this, obj);
}
@Override
public int hashCode() {
return BusinessIdentity.getHashCode(this);
}
}
这是我的测试用例:
// Create Rules to validate structure for POJO_PACKAGE
pojoValidator.addRule(new NoPublicFieldsRule());
pojoValidator.addRule(new NoPrimitivesRule());
pojoValidator.addRule(new NoStaticExceptFinalRule());
pojoValidator.addRule(new GetterMustExistRule());
pojoValidator.addRule(new SetterMustExistRule());
pojoValidator.addRule(new NoNestedClassRule());
// Create Testers to validate behaviour for POJO_PACKAGE
pojoValidator.addTester(new DefaultValuesNullTester());
pojoValidator.addTester(new SetterTester());
pojoValidator.addTester(new GetterTester());
for (PojoClass pojoClass : pojoClasses) {
pojoValidator.runValidation(pojoClass);
}
我收到以下异常:
com.openpojo.business.exception.BusinessException: Field required and can't be null [PojoFieldImpl
如果我从 Employee 类中删除对 Person 的引用,则测试不会引发任何异常。