### Question:
TableIndexes { public TableIndex getBestTableIndexMatch(List<String> fields) { if(fields == null || fields.size() == 0) return null; if(fields.size() == 1) return getTableIndex(fields.get(0)); Set<String> otherFields = new HashSet<>(fields); TableIndex bestIndexMatch = null; for(String field : fields) { List<TableIndex> tableIndexSet = fieldToIndexSetMap.get(field); if(tableIndexSet == null || tableIndexSet.size() == 0) continue; Optional<TableIndex> tableIndexSearch = tableIndexSet.stream() .filter(tableIndex -> otherFields.contains(tableIndex.getSortKey())) .findAny(); if(tableIndexSearch.isPresent()) return tableIndexSearch.get(); if(bestIndexMatch == null) bestIndexMatch = tableIndexSet.get(0); } return bestIndexMatch; }  TableIndexes withPrimaryKey(String fieldName); TableIndexes withIndex(String indexName, String fieldName); TableIndexes withIndex(String indexName, String fieldName, String sortKey); TableIndexes withIndex(TableIndex tableIndex); boolean isPrimary(String fieldName); TableIndex getTableIndex(String fieldName); TableIndex getBestTableIndexMatch(List<String> fields);  }### Answer:
@Test(dataProvider = "getBestTableIndexMatchProvider") public void testGetBestTableIndexMatch(TableIndexes tabledIndexes, List<String> fields, TableIndex expectedIndex) { Assert.assertEquals(tabledIndexes.getBestTableIndexMatch(fields), expectedIndex); }