方法isEqualToComparingFieldByFieldRecursively不使用RuntimeException对象。即使我们在预期的RuntimeException中更改RuntimeException消息,检查也始终返回true。
assertThat(caughtException).as("The Runtime exception")
.usingComparatorForType(ComparatorCollection.getDateComparator(MAX_ALLOWABLE_SEC_FOR_EQ),
LocalDateTime.class)
.usingComparatorForType(ComparatorCollection.getXmlDateComparator(MAX_ALLOWABLE_SEC_FOR_EQ),
XMLGregorianCalendar.class)
.isEqualToComparingFieldByFieldRecursively(expectedResults));
// caughtException.message and expectedResults.message are different but return true
assertThat(caughtException).as("The Runtime exception")
.usingComparatorForType(ComparatorCollection.getDateComparator(MAX_ALLOWABLE_SEC_FOR_EQ),
LocalDateTime.class)
.usingComparatorForType(ComparatorCollection.getXmlDateComparator(MAX_ALLOWABLE_SEC_FOR_EQ),
XMLGregorianCalendar.class)
.isEqualToComparingFieldByFieldRecursively(expectedResults)
// The recursively check don't work with the RuntimeException message
.isEqualToComparingOnlyGivenFields(expectedResults, "message");
我们已经做了一些测试,第二个例子工作(当我们强制检查attribut消息时)。
答案 0 :(得分:1)
这是检索要比较的字段的代码的旧限制,忽略java.lang
中的任何类型(以避免按字段比较Object
字段)。
这太激烈了,需要放松,已经创建了这个bug来跟踪问题https://github.com/joel-costigliola/assertj-core/issues/1224。