How to validate for "[]" empty array

5,098 views
Skip to first unread message

fret...@gmail.com

unread,
Feb 17, 2015, 4:16:26 AM2/17/15
to rest-a...@googlegroups.com
I am trying to validate response for the key A in below JSON  response

{
   
"T": 1,
   
"A": [
       
   
]
}



This is the code I am using

 
   
        given
().
            contentType
("application/json; charset=utf-8").
            body
(requestFormat).
            expect
().statusCode(200).
         
when().
             post
(baseURl).
         
then().
             log
().body().
             assertThat
().body("T", equalTo(1)).
            assertThat
().body("A",equalTo("[]"));


         

My tests always fails but I can't see any difference in the log

java.lang.AssertionError: JSON path A doesn't match.
Expected: []
  Actual: []


How do I check for  empty array for a certain key ?


Johan Haleby

unread,
Feb 17, 2015, 4:27:27 AM2/17/15
to rest-a...@googlegroups.com
Hi,

Use the "empty()" Hamcrest matcher:

.. then().body("A", empty());

/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages