### Question:
TextSelection extends Selection { @Override public void pasteAtEndOf(Selection positionItem) throws InvalidNavigationException { if (validate() == false) { throw new InvalidNavigationException("No matched string at this position"); } int indexOfNew = 0; OdfElement newElement = positionItem.getElement(); if (positionItem instanceof TextSelection) { indexOfNew = ((TextSelection) positionItem).getIndex() + ((TextSelection) positionItem).getText().length(); newElement = ((TextSelection) positionItem).getContainerElement(); } OdfTextSpan textSpan = getSpan((OdfFileDom) positionItem.getElement().getOwnerDocument()); mIsInserted = false; insertSpan(textSpan, indexOfNew, newElement); adjustStyle(newElement, textSpan, null); SelectionManager.refreshAfterPasteAtEndOf(this, positionItem); } TextSelection(String text, OdfElement containerElement, int index); @Override OdfElement getElement(); OdfElement getContainerElement(); @Override int getIndex(); String getText(); @Override void cut(); void applyStyle(OdfStyleBase style); void replaceWith(String newText); @Override void pasteAtFrontOf(Selection positionItem); @Override void pasteAtEndOf(Selection positionItem); void addHref(URL url); @Override String toString();  }### Answer:
@Test public void testPasteAtEndOf() { search = null; search = new TextNavigation("delete", doc); TextSelection sel = null; TextNavigation search1 = new TextNavigation("change", doc); if (search1.hasNext()) { sel = (TextSelection) search1.getCurrentItem(); } int i = 0; while (search.hasNext()) { TextSelection item = (TextSelection) search.getCurrentItem(); i++; try { sel.pasteAtEndOf(item); } catch (InvalidNavigationException e) { Assert.fail(e.getMessage()); } } int j = 0; search = new TextNavigation("deletechange", doc); while (search.hasNext()) { j++; } Assert.assertTrue(i == j); try { doc.save(ResourceUtilities.getTestOutputFile(SAVE_FILE_COPYTO1)); } catch (Exception e) { Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testPasteAtEndOf() { search = null; search = new TextNavigation("delete", doc); TextSelection sel = null; TextNavigation search1 = new TextNavigation("change", doc); if (search1.hasNext()) { sel = (TextSelection) search1.getCurrentItem(); } int i = 0; while (search.hasNext()) { TextSelection item = (TextSelection) search.getCurrentItem(); i++; try { sel.pasteAtEndOf(item); } catch (InvalidNavigationException e) { Assert.fail(e.getMessage()); } } int j = 0; search = new TextNavigation("deletechange", doc); while (search.hasNext()) { j++; } Assert.assertTrue(i == j); try { doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_COPYTO1)); } catch (Exception e) { Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }