### Question:
Cursor { public int toCursorOffset(int documentOffset) { return segment.toTextOffset(documentOffset); } Cursor(TextSegment segment); int getOffset(); int getOffset(int cursorOffset); int toCursorOffset(int documentOffset); char getChar(); char getChar(int offset); boolean hasChar(); String getText(int offset, int endIndex); char getPrevious(); boolean hasPrevious(); boolean hasPrevious(int offset); char getPrevious(int offset); char getNext(); char getNext(int offset); String getTextAtOffset(); String getTextAtOffset(int length); boolean hasNext(); boolean hasNext(int offset); Matcher matcher(Pattern pattern); Matcher matcher(int offset, Pattern pattern); void advance(); void advance(int count); void rewind(int count); void rewind(); Line getLineAtOffset();  }### Answer:
@Test(expected = IllegalArgumentException.class) public void toCursorOffset() { Cursor cursor = new Cursor(new TextSegment(ImmutableList.of(new Line(1, 10, "abc")))); assertEquals(0, cursor.toCursorOffset(10)); assertEquals(2, cursor.toCursorOffset(12)); cursor.toCursorOffset(9); }
@Test public void toCursorOffset() { Cursor cursor = new Cursor(new TextSegment(ImmutableList.of(new Line(1, 10, "abc")))); assertEquals(0, cursor.toCursorOffset(10)); assertEquals(2, cursor.toCursorOffset(12)); thrown.expect(IllegalArgumentException.class); cursor.toCursorOffset(9); }