Re: [rest-assured] Matching Integer vs Long in body

1,730 views
Skip to first unread message

Johan Haleby

unread,
Mar 19, 2013, 12:07:49 PM3/19/13
to rest-a...@googlegroups.com
Hi, 

No that is not supported. You could write your own Hamcrest matcher that e.g. converts the actual number and the expected number to long and then compares them. In the next version of Rest Assured (you can try it out if you build from source) you can configure all numbers to be returned as BigDecimal instead.

Regards,
/Johan

On Tue, Mar 19, 2013 at 4:36 PM, Jason Watson <po...@jhop.com> wrote:

I'm trying to compare a Long to an id value in a response.  I understand that an Integer 123 does not equals() a Long 123L, but is there a better way to make this comparison?  Is there a way to tell body() to treat "id" as a Long?  Is there a way to have the matcher compare the numeric value instead of just equals()?

Long val = Long.valueOf(123L)

expect().body("id", equalTo(val)) ...

JSON path id doesn't match.
Expected: <123L>
  Actual: 123


Using Long.intValue() works for small numbers, but I'm looking for a solution that won't overflow.
expect().body("id", equalTo(val.intValue())) ...

Thanks,
Jason


--
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/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages