How to compare\assert double values in rest assured

Dmitriy Zholudev :

I'm trying to compare\assert double from a JSON with java primitive double value. What is the proper way to do it?

I used simple and regular way to do it, using Matchers.equalTo method, see below

public class A{
       private static double someJavaDouble = 12
}
given().
        header(.....).
when().
        get(url).
then().
        statusCode(200)
        body("value", Matchers.equalTo(someJavaDouble))

Response of get(url) is JSON:

{
    "success": true,
    "currentValue": 12.0
}

In the code above I get this error:

JSON path currentValue doesn't match.
Expected: <12.0>
  Actual: 12.0

p.s. it works if

body("value", Matchers.equalTo(12f))
Sumit Bhardwaj :

Since the value returned by JSON Serializer is Double, not the primitive data type double.
You can get double value from Double Double.doubleValue() or convert double to Double new Double(someJavaDouble)

body("value", Matchers.equalTo(new Double(someJavaDouble)))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=166324&siteId=1