@Test
public void testSortingMap() {

  Map<String, String> testMap = getTestMap();
  // Test ascent sorting
  Map<String, String> sortedMap = sortMapByValue(testMap, true);
  assertEquals(testMap.size(), sortedMap.size());
  TreeSet<Object> sortedValues = new TreeSet<>((s1, s2) -> {
    if (s1 instanceof Comparable && s2 instanceof Comparable) {
      return ((Comparable) s1).compareTo(s2);
    } else
      return -1;
  });
  sortedValues.addAll(testMap.values());
  Iterator<Entry<String, String>> iteratorSortedMap = sortedMap.entrySet().iterator();
  Iterator<Object> iteratorSortedValues = sortedValues.iterator();
  while (iteratorSortedMap.hasNext()) {
    Entry<String, String> entry = iteratorSortedMap.next();
    Object value = iteratorSortedValues.next();
    assertEquals(value, entry.getValue());
  }
  // Test descent sorting
  sortedMap = sortMapByValue(testMap, false);
  assertEquals(testMap.size(), sortedMap.size());
  sortedValues = new TreeSet<>((s1, s2) -> -((Comparable) s1).compareTo(s2));
  sortedValues.addAll(testMap.values());
  iteratorSortedMap = sortedMap.entrySet().iterator();
  iteratorSortedValues = sortedValues.iterator();
  while (iteratorSortedMap.hasNext()) {
    Entry<String, String> entry = iteratorSortedMap.next();
    Object value = iteratorSortedValues.next();
    assertEquals(value, entry.getValue());
  }
}