0

I am fairly new at this. I am trying assert that elements are positioned in descending order and first one is latest dated one(2019,2018,2017,2016 etc)

here are the elements with DATES:

}-->2017/2018

}-->2016/2017

}-->2015/2016

}-->2014/2015

Tshili
  • 51
  • 3
  • Can you elaborate more about your question? What do you want to get? Do you want to sort a list? – Bowen Mar 27 '19 at 08:19

1 Answers1

-1

Solution using com.google.common.collect is here:

boolean isSorted = Ordering.natural().reverse().isOrdered(actualDates);
Assert.assertTrue(isSorted);

You can use sort and assert using TestNG:

// Assume it's your actual dates to check
List<String> actualDates = new ArrayList<>();
actualDates.add("2014/2015");
actualDates.add("2016/2017");
actualDates.add("2017/2018");
actualDates.add("2015/2016");

// Create new list,  add all from actual list and order it. 
List<String> sortedDates = new ArrayList<>(actualDates);
sortedDates.sort(Comparator.reverseOrder());

Assert.assertEquals(actualDates, sortedDates);
Sers
  • 12,047
  • 2
  • 12
  • 31