I am trying to write a test case for the REST API part of my website. I use dropwizard.
@Test
public void getAll(){
assertThat(resources.client().target("/blogcomments").request().get(List.class))
.isEqualTo(GsonInstance.INSTANCE.getGson().toJson(list));
verify(dao).getAll(list);
}
And what I get is like this :
[{"comment"="comment", "date"=1464906153750L, "id"=1, "name"="name", "url"="url"}]
In the assert
above, if I use an object to compare, actually I am using [api.BlogComment@e3e181ab]
.
If I use Gson to convert object to json like this:
@Test
public void getAll(){
assertThat(resources.client().target("/blogcomments").request().get(List.class))
.isEqualTo(GsonInstance.INSTANCE.getGson().toJson(list));
verify(dao).getAll(POJOs.BlogCommentPOJO.toString());
}
What I got is:
org.junit.ComparisonFailure:
Expected :"[{"id":1,"url":"url","comment":"comment","date":"Jun 2, 2016 6:27:50 PM","name":"name"}]"
Actual :[{"comment"="comment", "date"=1464906470531L, "id"=1, "name"="name", "url"="url"}]
How to deal with the Date format? How to compare whether two JSON are equal?