为什么这个测试用例会抛出异常“节点不真实”,即使它的大小是 1?
package foo.bar
import grails.test.*
import org.codehaus.jackson.JsonFactory
import org.codehaus.jackson.JsonNode
import org.codehaus.jackson.map.ObjectMapper
import org.junit.Test
class MyTest{
    @Test
    void testJSonNode() {
        ObjectMapper mapper = new ObjectMapper(new JsonFactory())
        JsonNode node = mapper.readTree('{"foo":"bar"}')
        assert node.size() == 1
        assert node.iterator().hasNext() == true
        if (!node) {
            throw new Exception("Node is not truthful")
        }
    }
}
一些背景资料:
- 如果我if (!node)改为if (node == null)
- 我猜这是Groovy Truth的问题
- node 是org.codehaus.jackson.node.ObjectNode的一个实例
- 这曾经在 org.codehaus.jackson:jackson-mapper-asl:1.6.5 中工作
- 我在 org.codehaus.jackson:jackson-mapper-asl:1.9.11 中看到了这个问题
- ObjectNode 实现 Iterable