How do assert one list in another list with same order

761 Views Asked by At

I have one list which contains recent 5 dates of order

List<String> recentFiveOrdersDates = new ArrayList<>();

values in list are :

["20/07/2018", "19/07/2018", "18/07/2018", "18/07/2018", "18/07/2018"]

I have another list which contains all dates of order:

List<String> AllOrderDates = new ArrayList<>();

And values in this list are :

["20/07/2018", "19/07/2018", "18/07/2018", "18/07/2018", "18/07/2018", "17/07/2018", "17/07/2018", "16/07/2018", "16/07/2018", "12/07/2018", "12/07/2018", "17/05/2018"]

Now I want to assert the recent five order list in the all orders list. Is it possible to verify they're in the same order?

I have used assertThat() method of hamcrest but I'm not sure it work in same way

assertThat(AllOrderDates, contains(recentFiveOrdersDates.toArray()));
1

There are 1 best solutions below

1
Shanu Gupta On

The contains(T... items) method cater to the ordering already.

If you do not want ordering you may use containsInAnyOrder(T... items).