Reputation: 11
I have one response object of a REST call which is having JSON data. I am using groovy to verify one key value either it should be a string or null
For example
assert response.data.item.key
So key can be a string or a null. How can I put assertion on this key value?
Upvotes: 1
Views: 1154
Reputation: 171194
Are you sure you want only a String?
If you use a groovy string or some other char sequence checking its class equals String will fail
def key = response.data.item.key
assert key == null || key instanceof CharSequence
May be better...
Upvotes: 1
Reputation: 20707
Assert could look like:
def key = response.data.item.key
assert null == key || String == key.getClass()
Upvotes: 1