### Question:
TermsReplaceInstruction implements ReplaceInstruction { @Override public void apply(final List<CharSequence> seq, final int start, final int exclusiveOffset, final CharSequence wildcardMatch) { IntStream.range(0, exclusiveOffset).forEach(i -> seq.remove(start)); seq.addAll(start, replacementTerms); } TermsReplaceInstruction(final List<? extends CharSequence> replacementTerms); @Override void apply(final List<CharSequence> seq, final int start, final int exclusiveOffset,
                      final CharSequence wildcardMatch);  }### Answer:
@Test public void testRemoveOneTerm() { TermsReplaceInstruction replaceInstruction = new TermsReplaceInstruction(list()); List<CharSequence> input = list("a", "b"); replaceInstruction.apply(input, 1, 1); assertThat(strlist(input)).containsExactly("a"); }
@Test public void testRemoveManyTerms() { TermsReplaceInstruction replaceInstruction = new TermsReplaceInstruction(list()); List<CharSequence> input = list("a", "b", "c"); replaceInstruction.apply(input, 1, 2); assertThat(strlist(input)).containsExactly("a"); }
@Test public void testReplaceOneTermByOne() { TermsReplaceInstruction replaceInstruction = new TermsReplaceInstruction(list("c")); List<CharSequence> input = list("a", "b"); replaceInstruction.apply(input, 1, 1); assertThat(strlist(input)).containsExactly("a", "c"); }
@Test public void testReplaceOneTermByMany() { TermsReplaceInstruction replaceInstruction = new TermsReplaceInstruction(list("c", "d")); List<CharSequence> input = list("a", "b"); replaceInstruction.apply(input, 0, 1); assertThat(strlist(input)).containsExactly("c", "d", "b"); input = list("a", "b"); replaceInstruction.apply(input, 1, 1); assertThat(strlist(input)).containsExactly("a", "c", "d"); input = list("a", "b", "e"); replaceInstruction.apply(input, 1, 1); assertThat(strlist(input)).containsExactly("a", "c", "d", "e"); }
@Test public void testReplaceManyTermsByMany() { TermsReplaceInstruction replaceInstruction = new TermsReplaceInstruction(list("d", "e", "f")); List<CharSequence> input = list("a", "b", "c"); replaceInstruction.apply(input, 0, 2); assertThat(strlist(input)).containsExactly("d", "e", "f", "c"); input = list("a", "b", "c"); replaceInstruction.apply(input, 1, 2); assertThat(strlist(input)).containsExactly("a", "d", "e", "f"); }