为什么“放心的人”说“验证不匹配”,但排除匹配“实际”呢?

时间:2019-01-04 17:52:03

标签: java rest-assured

我正在尝试使用RestAssured验证此JSON:

{
    "valueBounds": [
        {
            "bound": {
                "min": 1.0,
                "max": 4.2
            },
            "date": "2019-01-04T18:40:28.204+0100"
        }
    ],
}

使用以下代码:

given().when().get(rootPath + "/test/").then().statusCode(200).log().body().
    body("valueBounds.bound.min", hasItems(1.0));

为什么我发现它们不匹配:

java.lang.AssertionError: 1 expectation failed.
JSON path valueBounds.bound.min doesn't match.
Expected: (a collection containing <1.0>)
Actual: [1.0]

我尝试使用Arrays.asList(1.0),但这不是问题。

1 个答案:

答案 0 :(得分:-1)

解决方案是在数字后面添加f:

"valueBounds.bound.min", hasItems(1.0f)