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