@Test
void testSortByAge() {

    final FindTaskProgressCriteria criteria = new FindTaskProgressCriteria();
    final TaskManagerTreeAction treeAction = new TaskManagerTreeAction();
    final Map<TaskId, TaskProgress> totalMap = createMap(criteria);
    List<TaskProgress> sortedList;
    // Test sorting by age.
    criteria.setSort(FindTaskProgressCriteria.FIELD_AGE, false, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getAgeMs() <= v2.getAgeMs());
    criteria.setSort(FindTaskProgressCriteria.FIELD_AGE, true, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getAgeMs() >= v2.getAgeMs());
    // Test sorting by submit time.
    criteria.setSort(FindTaskProgressCriteria.FIELD_SUBMIT_TIME, false, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getSubmitTimeMs() <= v2.getSubmitTimeMs());
    criteria.setSort(FindTaskProgressCriteria.FIELD_SUBMIT_TIME, true, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getSubmitTimeMs() >= v2.getSubmitTimeMs());
    // Test sorting by name.
    criteria.setSort(FindTaskProgressCriteria.FIELD_NAME, false, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getTaskName().compareTo(v2.getTaskName()) <= 0);
    criteria.setSort(FindTaskProgressCriteria.FIELD_NAME, true, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getTaskName().compareTo(v2.getTaskName()) >= 0);
    // Test sorting by user.
    criteria.setSort(FindTaskProgressCriteria.FIELD_USER, false, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getUserName().compareTo(v2.getUserName()) <= 0);
    criteria.setSort(FindTaskProgressCriteria.FIELD_USER, true, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getUserName().compareTo(v2.getUserName()) >= 0);
    // Test sorting by node.
    criteria.setSort(FindTaskProgressCriteria.FIELD_NODE, false, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getNodeName().compareTo(v2.getNodeName()) <= 0);
    criteria.setSort(FindTaskProgressCriteria.FIELD_NODE, true, false);
    sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction);
    testList(sortedList, (v1, v2) -> v1.getNodeName().compareTo(v2.getNodeName()) >= 0);
}