简体   繁体   中英

How do assert one list in another list with same order

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()));

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM