Issue
This is my mock response, where I need to assert a particular field (type) as null. It always throws me exception as
java.lang.AssertionError: expected null, but was:<[null]>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotNull(Assert.java:755)
at org.junit.Assert.assertNull(Assert.java:737)
at org.junit.Assert.assertNull(Assert.java:747)
Mock response
{
"locations": [
{
"type": null,
"statusDt": "2018-08-15",
}
]
}
I'm doing assertion in the followig way
assertNull(locationResponse.getLocations().stream().map(location -> location.getType()).collect(Collectors.toList()));
Solution
Seems like as a result of collect()
operation you get a List that contains only one element null
.
Please try to get first element from that list
assertNull(locationResponse.getLocations().stream().map(location -> location.getType()).collect(Collectors.toList()).get(0));
Answered By - Ivan