0

I'm developing an Api Automation test using Rest-Assured. This is my API response:


    {
        "is_active": false,
        "token": null
    } 

I want to assured that Token is null, so I developed the following code:


    public void responseLoginFacebookTokenSemCad (String srtToken) {
        boolean responseToken = Boolean.valueOf(srtToken);

        Assert.assertTrue(ResponseHolder.getResponseBody().contains("token"));
        boolean resBodyLoginFacebookSemCad = ResponseHolder.getResponseJson().get("token");
        Assert.assertEquals(resBodyLoginFacebookSemCad, responseToken);

    }

The String srtToken is like "null". I'm receiving the following message:

java.lang.NullPointerException at stepDefinition.dataMap.responseLoginFacebookTokenSemCad(dataMap.java:409) at stepDefinition.steps.validaTokenLoginFacebook(steps.java:277) at ✽.no response no compo token retornara null(file:src/test/java/Autobusca/Ford/loginFacebook.feature:23)

How can I validate it? Thanks

Cleicy Guião
  • 111
  • 1
  • 20
  • Which line throws the exception? – Fenio May 08 '19 at 14:14
  • 2
    Use the wrapper `Boolean` instead of the primitive `boolean` type, the former allows `null`s whereas the latter will not – Lino May 08 '19 at 14:15
  • check if ResponseHolder.getResponseJson().get("token") is null; if it is not, assign the aquired value. boolean will take false by default if not assigned, so just check if it isn't null – aran May 08 '19 at 14:23

1 Answers1

-2

Can you try this assertEquals(null, ResponseHolder.getResponseBody().get("token"));?