我找到了一种忽略 2 个特定标签名称的特定比较的方法。
如果有人需要,我会在这里给出答案
首先制作一个自定义的DifferenceEvaluator:
public class IgnoreTagNameDifferenceEvaluator implements DifferenceEvaluator {
Map<String,String> map;
public IgnoreTagNameDifferenceEvaluator(Map<String,String> map){
this.map = map;
}
@Override
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
if (outcome == ComparisonResult.EQUAL) return outcome; // only evaluate differences.
if(comparison.getType() == ComparisonType.ELEMENT_TAG_NAME){
String value = map.get(comparison.getControlDetails().getValue());
if(value != null && value.equals(comparison.getTestDetails().getValue())){
return ComparisonResult.SIMILAR;
}
}
return outcome;
}
}
然后像这样将它链接到 diffBuilder :
diffBuilder = diffBuilder.withDifferenceEvaluator(DifferenceEvaluators.chain(
DifferenceEvaluators.Default, new IgnoreTagNameDifferenceEvaluator(tagMap)));