### Question:
Utilities { public static String sortInhabitantsDescriptor(String in, boolean innerSort) { ArrayList<String> lines = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(in.getBytes()))); String line; try { while (null != (line = reader.readLine())) { if (!line.startsWith("#") && !line.isEmpty()) { lines.add(innerSort ? innerSort(line) : line); } } } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(lines); StringBuilder sb = new StringBuilder(); for (String oline : lines) { sb.append(oline).append("\n"); } return sb.toString(); }  static String sortInhabitantsDescriptor(String in, boolean innerSort);  }### Answer:
@Test public void testSortInhabitants() { StringBuilder sb = new StringBuilder(); sb.append("class=service1,index=contract1:name1,index=annotation1\n"); sb.append("class=service2,index=contract1,index=annotation1\n"); sb.append("class=service3,index=contract2:name2,index=contract1:name2,index=annotation2,index=annotation1,b=2,a=1\n"); sb.append("class=service4,a=1\n"); String expected = sb.toString(); String output = Utilities.sortInhabitantsDescriptor(testCase(), false); assertEquals(expected, output); }
@Test public void testSortInhabitantsAndContents() { StringBuilder sb = new StringBuilder(); sb.append("class=service1,index=annotation1,index=contract1:name1\n"); sb.append("class=service2,index=annotation1,index=contract1\n"); sb.append("class=service3,index=annotation1,index=annotation2,index=contract1:name2,index=contract2:name2,a=1,b=2\n"); sb.append("class=service4,a=1\n"); String expected = sb.toString(); String output = Utilities.sortInhabitantsDescriptor(testCase(), true); assertEquals(expected, output); }
@Test public void testEmptySort() { String output = Utilities.sortInhabitantsDescriptor("", true); assertEquals("", output); }