### Question:
SequenceItem implements Comparable<SequenceItem> { public static String getDittedString(List<SequenceItem> itemList, int totalLength) { StringBuilder sb = new StringBuilder(); int symbolsWritten = 0; for (SequenceItem currentItem : itemList) { if (currentItem.getIndex() < symbolsWritten) { throw new IllegalArgumentException( "itemList must be in ascending order of item index"); } while (currentItem.getIndex() > symbolsWritten) { sb.append("."); symbolsWritten++; } sb.append(currentItem.getSymbol()); symbolsWritten++; } if (symbolsWritten > totalLength) { throw new IllegalArgumentException("mismatch between itemList and totalLength"); } while (symbolsWritten < totalLength) { sb.append("."); symbolsWritten++; } return sb.toString(); } SequenceItem(String item, int index); String getSymbol(); int getIndex(); @Override int hashCode(); @Override boolean equals(Object obj); static String getDittedString(List<SequenceItem> itemList, int totalLength); @Override String toString(); @Override int compareTo(SequenceItem arg0);  }### Answer:
@Test public void emptySequenceTest() { List<SequenceItem> emptyList = new ArrayList<SequenceItem>(); String dittedString = SequenceItem.getDittedString(emptyList, 0); assertEquals("", dittedString); dittedString = SequenceItem.getDittedString(emptyList, 3); assertEquals("...", dittedString); }
@Test public void noDitsTest() { List<SequenceItem> testList = new ArrayList<SequenceItem>(); testList.add(new SequenceItem("A", 0)); String testString = SequenceItem.getDittedString(testList, 1); assertEquals("A", testString); testList.add(new SequenceItem("B", 1)); testString = SequenceItem.getDittedString(testList, 2); assertEquals("AB", testString); }
@Test public void ditsTest() { List<SequenceItem> testList = new ArrayList<SequenceItem>(); testList.add(new SequenceItem("A", 1)); String testString = SequenceItem.getDittedString(testList, 2); assertEquals(".A", testString); testList.add(new SequenceItem("B", 2)); testString = SequenceItem.getDittedString(testList, 3); assertEquals(".AB", testString); testList.add(new SequenceItem("C", 5)); testString = SequenceItem.getDittedString(testList, 6); assertEquals(".AB..C", testString); testString = SequenceItem.getDittedString(testList, 10); assertEquals(".AB..C....", testString); }
@Test(expected = IllegalArgumentException.class) public void outOfOrderTest() { List<SequenceItem> testList = new ArrayList<SequenceItem>(); testList.add(new SequenceItem("A", 1)); testList.add(new SequenceItem("B", 0)); String testString = SequenceItem.getDittedString(testList, 2); System.out.println("Test failed: " + testString); }