assertj/assertj-examples

isSorted() is not working with date

siva90144 opened this issue · 1 comments

Hi,

I have a scenario as below.
arrayList countryList =new arrayList();
I have taken arrayList and added all dates to it . Now I need to verify those are in ascending order or not.
When i used below assert its giving error but actually its not an error.
assertThat(sortAscending(countryList)).as("Ascending Sorted order is: "+countryList).isSorted();
Dates sorted in ascending order(MM/DD/YYYY):
09/08/2017
11/08/2017
12/18/2017
12/28/2017
01/08/2018
02/08/2018
03/08/2018

it is giving error at below dates
12/28/2017, 01/08/2018

Can you please help me how to assert date filed with assertJ assertions ?

Also how to verify Descending order with assertJ assertions?

isSorted relies on the element compareTo method (Date in your case) and checks that consecutive elements are in order.

Can you double check your sortAscending implementation ? My gut feeling is that it does not take the time part of the date.
If you want further help please provide a test case that we can run to reproduce the issue.

One way to to check the reverse order is to create the opposite comparator and use isSortedAccordingTo.

I'm closing this issue as it should have been raised in assertj-core (assertj-examples is just a demo project) but feel free to continue commenting it.