ArtistIndexService { protected Map<Character, String> createIndexesFromExpression(String expr) { Map<Character, String> index = new LinkedHashMap<>(); String[] expressions = StringUtils.split(expr, ' '); for (String expression : expressions) { int separatorIndex = expression.indexOf('('); if (separatorIndex == -1 && expression.length() == 1) { index.put(expression.charAt(0), expression); } else if (separatorIndex > 0) { String title = expression.substring(0, separatorIndex); for (int i = separatorIndex + 1; i < expression.length(); i++) { if (expression.charAt(i) != ')') { index.put(expression.charAt(i), title); } } } } if (!index.containsKey(HASH_CHAR)) { index.put(HASH_CHAR, HASH_STR); } return index; }  Map<String, List<Artist>> getIndexedArtists(List<Artist> artists); SortedMap<String, List<Artist>> getIndexedArtists(List<Integer> indexes, String indexLetter, List<Artist> artists); void setSettingsService(SettingsService settingsService);  }
@Test public void buildsLetterIndex() { String userInput = "A B C X-Z(XYZ)"; Map<Character, String> map = artistIndexService.createIndexesFromExpression(userInput); Assert.assertNotNull(map); Assert.assertEquals(7, map.keySet().size()); Assert.assertTrue(map.keySet().contains('A')); Assert.assertTrue(map.keySet().contains('B')); Assert.assertTrue(map.keySet().contains('C')); Assert.assertTrue(map.keySet().contains('X')); Assert.assertTrue(map.keySet().contains('Y')); Assert.assertTrue(map.keySet().contains('Z')); Assert.assertTrue(map.keySet().contains('#')); Assert.assertTrue(map.get('A').equals("A")); Assert.assertTrue(map.get('B').equals("B")); Assert.assertTrue(map.get('C').equals("C")); Assert.assertTrue(map.get('X').equals("X-Z")); Assert.assertTrue(map.get('Y').equals("X-Z")); Assert.assertTrue(map.get('Z').equals("X-Z")); Assert.assertTrue(map.get('#').equals("#")); }