AssertJ - 方法 isEqualToComparingFieldByFieldRecursively 不适用于 RuntimeException 对象

AssertJ - The method isEqualToComparingFieldByFieldRecursively don't work with RuntimeException object

总结

方法 isEqualToComparingFieldByFieldRecursively 不适用于 RuntimeException 对象。即使我们更改预期的 RuntimeException 中的 RuntimeException 消息,检查也总是 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));
            // 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");

我们进行了一些测试,第二个示例工作(当我们强制检查属性消息时)。

这是检索要比较的字段的代码的旧限制,它忽略了 java.lang 中的任何类型(以避免逐个字段比较 Object)。

这太过激了,需要放宽,已创建此错误来跟踪问题 https://github.com/joel-costigliola/assertj-core/issues/1224