### Question:
Sequence { public int getIndexAfterFirstInstance(List<SequenceItem> prefixSequence) { if (prefixSequence == null) { return 0; } if (prefixSequence.isEmpty()) { return 0; } int index = 0; for (SequenceItem item : prefixSequence) { if ((item.getIndex() + 1) > sequence.length()) { index = -1; break; } String symbol = sequence.substring(item.getIndex(), item.getIndex() + 1); if (!symbol.equals(item.getSymbol())) { index = -1; break; } index = item.getIndex() + 1; } return index; } Sequence(String sequence, int count); String getSequenceAsString(); int getCount(); int getIndexAfterFirstInstance(List<SequenceItem> prefixSequence);  }### Answer:
@Test public void itemDoesntOccurTest() { prefixSequence.add(new SequenceItem("A", 0)); prefixIndex = testSequence.getIndexAfterFirstInstance(prefixSequence); assertEquals(-1, prefixIndex); }
@Test public void prefixTestOne() { prefixSequence.add(new SequenceItem("A", 1)); prefixSequence.add(new SequenceItem("B", 2)); prefixIndex = testSequence.getIndexAfterFirstInstance(prefixSequence); assertEquals(-1, prefixIndex); }
@Test public void prefixTestTwo() { prefixSequence.add(new SequenceItem("B", 1)); prefixSequence.add(new SequenceItem("A", 2)); prefixIndex = testSequence.getIndexAfterFirstInstance(prefixSequence); assertEquals(-1, prefixIndex); }
@Test public void prefixTestThree() { prefixSequence.add(new SequenceItem("C", 0)); prefixSequence.add(new SequenceItem("A", 1)); prefixSequence.add(new SequenceItem("A", 2)); prefixSequence.add(new SequenceItem("B", 3)); prefixSequence.add(new SequenceItem("C", 4)); prefixIndex = testSequence.getIndexAfterFirstInstance(prefixSequence); assertEquals("CAABC".length(), prefixIndex); }
@Test public void prefixTestFour() { prefixSequence.add(new SequenceItem("C", 0)); prefixSequence.add(new SequenceItem("A", 1)); prefixSequence.add(new SequenceItem("A", 2)); prefixSequence.add(new SequenceItem("B", 3)); prefixSequence.add(new SequenceItem("C", 4)); prefixSequence.add(new SequenceItem("A", 5)); prefixIndex = testSequence.getIndexAfterFirstInstance(prefixSequence); assertEquals(-1, prefixIndex); }