如何实现 ExampleMatcher,从我的类中随机只包含一个属性而忽略其他属性?
假设我的班级是这样的:
Public Class Teacher() {
String id;
String name;
String address;
String phone;
int area;
..other properties is here...
}
如果我想按名称匹配:
Teacher TeacherExample = new Teacher("Peter");
ExampleMatcher matcher = ExampleMatcher.matchingAny()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase()
.withIgnorePaths("id", "address", "phone","area",...); //no name
如果我想按地址匹配:
ExampleMatcher matcher = ExampleMatcher.matchingAny()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase()
.withIgnorePaths("id", "name", "phone","area",...); //no address
所以我需要重复withIgnorePaths(..)
如何避免这种情况?