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