@Test
public void getDistinctKeysAndCounts_SortByKeyDescending(){

    Connection connection = null;
    ResultSet resultSet = null;
    try {
        ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
        initWithTestData(connectionManager);
        connection = connectionManager.getConnection(null, noQueryOptions());
        resultSet = DBQueries.getDistinctKeysAndCounts(true, NAME, connection);
        Map<String, Integer> resultSetToMap = resultSetToMap(resultSet);
        assertEquals(3, resultSetToMap.size());
        Iterator<Map.Entry<String, Integer>> entriesIterator = resultSetToMap.entrySet().iterator();
        Map.Entry entry = entriesIterator.next();
        assertEquals("gps", entry.getKey());
        assertEquals(1, entry.getValue());
        entry = entriesIterator.next();
        assertEquals("airbags", entry.getKey());
        assertEquals(1, entry.getValue());
        entry = entriesIterator.next();
        assertEquals("abs", entry.getKey());
        assertEquals(2, entry.getValue());
    }finally {
        DBUtils.closeQuietly(resultSet);
        DBUtils.closeQuietly(connection);
    }
}