Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isSorted() is not working with date #43

Closed
siva90144 opened this issue Sep 10, 2018 · 1 comment
Closed

isSorted() is not working with date #43

siva90144 opened this issue Sep 10, 2018 · 1 comment

Comments

@siva90144
Copy link

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?

@joel-costigliola
Copy link
Member

joel-costigliola commented Sep 11, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants