lilinkevin / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

emptyArray() does not match an empty array #300

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I have a class RESTful Controller that returns a body with just

[]

Then I run these two lines of code on it.
get("collections").then().body("", empty());
get("collections").then().body("", emptyArray());

What is the expected output? What do you see instead?
I expect the first one to fail, and the second one to pass. Or POSSIBLY both to 
pass. But the second one fails.

What version of the product are you using? On what operating system?

Newest version of rest-assured

Please provide any additional information below.

This is the error it gives

java.lang.AssertionError: JSON path  doesn't match.
Expected: an empty array
  Actual: []

Original issue reported on code.google.com by Jazz...@gmail.com on 18 Jan 2014 at 12:18

GoogleCodeExporter commented 9 years ago
That's probably because it's represented as a List and not array. If there's 
such a thing as emptyList() then try that instead. I usually use "hasSize" 
instead:

get("collections").then().body("", hasSize(0));

Original comment by johan.ha...@gmail.com on 18 Jan 2014 at 10:42

GoogleCodeExporter commented 9 years ago
Thanks! I was able to get it working with the below code.

        get("collections").then().body("", emptyCollectionOf(List.class));

Original comment by Jazz...@gmail.com on 18 Jan 2014 at 2:45

GoogleCodeExporter commented 9 years ago
Great!

Original comment by johan.ha...@gmail.com on 18 Jan 2014 at 4:08