### Question:
TextDocument extends TextDocumentItem { public Position positionAt(int position) throws BadLocationException { ILineTracker lineTracker = getLineTracker(); return lineTracker.getPositionAt(position); } TextDocument(TextDocumentItem document);  TextDocument(String text, String uri); void setIncremental(boolean incremental); boolean isIncremental(); Position positionAt(int position); int offsetAt(Position position); String lineText(int lineNumber); String lineDelimiter(int lineNumber); Range getWordRangeAt(int textOffset, Pattern wordDefinition); void update(List<TextDocumentContentChangeEvent> changes);  }### Answer:
@Test public void testPositionAt() throws BadLocationException { TextDocument document = new TextDocument("abcd\nefgh", ""); Position position = document.positionAt(0); assertEquals(0, position.getLine()); assertEquals(0, position.getCharacter()); position = document.positionAt(4); assertEquals(0, position.getLine()); assertEquals(4, position.getCharacter()); position = document.positionAt(5); assertEquals(1, position.getLine()); assertEquals(0, position.getCharacter()); position = document.positionAt(9); assertEquals(1, position.getLine()); assertEquals(4, position.getCharacter()); BadLocationException ex = null; try { position = document.positionAt(10); } catch (BadLocationException e) { ex = e; } assertNotNull(ex); }
@Test public void testPositionAtEndLine() throws BadLocationException { TextDocument document = new TextDocument("abcd\n", ""); Position position = document.positionAt(4); assertEquals(0, position.getLine()); assertEquals(4, position.getCharacter()); position = document.positionAt(5); assertEquals(1, position.getLine()); assertEquals(0, position.getCharacter()); BadLocationException ex = null; try { position = document.positionAt(6); } catch (BadLocationException e) { ex = e; } assertNotNull(ex); document = new TextDocument("abcd\nefgh\n", ""); position = document.positionAt(9); assertEquals(1, position.getLine()); assertEquals(4, position.getCharacter()); position = document.positionAt(10); assertEquals(2, position.getLine()); assertEquals(0, position.getCharacter()); ex = null; try { position = document.positionAt(11); } catch (BadLocationException e) { ex = e; } assertNotNull(ex); }