### Question:
JavaLexed implements AutoCloseable { public LexicalElement remove(int i) { assertOpen(); return lexicalElements.remove(i); } JavaLexed(Source source); @Override void close(); Iterable<LexicalElement> lexicalElements(); LexicalElement get(int i); LexicalElement remove(int i); void removeRange(int start, int end); int replaceWith(List<LexicalElement>... lists); int replace(MatchResult result, List<LexicalElement>... lists); int replace(int start, int end, List<LexicalElement>... lists); void add(int index, LexicalElement le); int size(); JavaLexed match(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed find(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed sensitivity(int sensitivity); JavaLexed fromStart(); JavaLexed fromIndex(int i); Optional<java.util.regex.MatchResult> regexGroups(final String name); List<javax0.geci.javacomparator.LexicalElement> group(final String name); MatchResult result();  }### Answer:
@Test @DisplayName("Can remove a single lexical element.") void removesElement() { final var source = new TestSource("public static final"); final String lexed; try(final var sut = new JavaLexed(source)) { sut.remove(2); lexed = toLexicalString(sut); } Assertions.assertEquals("IDENTIFIER[public]\n" + "SPACING[ ]\n" + "SPACING[ ]\n" + "IDENTIFIER[final]\n", lexed); }
@Test @DisplayName("Can't remove element from out of bounds.") void removeElementThrowsExceptionOutOfBounds() { final var source = new TestSource("public final"); try(final var sut = new JavaLexed(source)) { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> sut.remove(-1)); Assertions.assertThrows(IndexOutOfBoundsException.class, () -> sut.remove(5)); } }