### Question:
JavaLexed implements AutoCloseable { public void removeRange(int start, int end) { assertStartEndOrder(start, end); assertOpen(); if (end > start) { lexicalElements.subList(start, end).clear(); } } 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't remove range with bigger start than end.") void removeRangeThrowsExceptionWhenWrongStartEndOrder() { final var source = new TestSource(""); try(final var sut = new JavaLexed(source)) { Assertions.assertThrows(IllegalArgumentException.class, () -> sut.removeRange(2, 1)); } }
@Test @DisplayName("Can't remove range if end is out of bounds.") void removeRangeThrowsExceptionWhenEndOutOfBounds() { final var source = new TestSource("public final"); try(final var sut = new JavaLexed(source)) { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> sut.removeRange(1, 5)); } }
@Test @DisplayName("Can't remove range if start is out of bounds.") void removeRangeThrowsExceptionWhenStartOutOfBounds() { final var source = new TestSource("public final"); try(final var sut = new JavaLexed(source)) { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> sut.removeRange(-1, 2)); } }
@Test @DisplayName("Can remove a range of lexical elements.") void removesRange() { final var source = new TestSource("final static private"); final String lexed; try(final var sut = new JavaLexed(source)) { sut.removeRange(1, 3); lexed = toLexicalString(sut); } Assertions.assertEquals("IDENTIFIER[final]\n" + "SPACING[ ]\n" + "IDENTIFIER[private]\n", lexed); }