### Question:
TextSelection extends Selection { @Override public void cut() throws InvalidNavigationException { if (validate() == false) { throw new InvalidNavigationException("No matched string at this position"); } OdfElement container = getContainerElement(); delete(mIndexInContainer, mMatchedText.length(), container); SelectionManager.refreshAfterCut(this); mMatchedText = ""; } 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 testCut() { search = null; search = new TextNavigation("delete", doc); TextSelection nextSelect = null; TextNavigation nextsearch = new TextNavigation("next", doc); if (nextsearch.hasNext()) { nextSelect = (TextSelection) nextsearch.getCurrentItem(); } int i = 0; while (search.hasNext()) { TextSelection item = (TextSelection) search.getCurrentItem(); i++; try { item.cut(); } catch (InvalidNavigationException e) { Assert.fail(e.getMessage()); } } Assert.assertTrue(8 == i); search = new TextNavigation("delete", doc); Assert.assertFalse(search.hasNext()); try { nextSelect.cut(); } catch (InvalidNavigationException e1) { Assert.fail(e1.getMessage()); } Assert.assertFalse(nextsearch.hasNext()); try { doc.save(ResourceUtilities.getTestOutputFile(SAVE_FILE_DELETE)); } 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 testCut() { search = null; search = new TextNavigation("delete", doc); TextSelection nextSelect = null; TextNavigation nextsearch = new TextNavigation("next", doc); if (nextsearch.hasNext()) { nextSelect = (TextSelection) nextsearch.getCurrentItem(); } int i = 0; while (search.hasNext()) { TextSelection item = (TextSelection) search.getCurrentItem(); i++; try { item.cut(); } catch (InvalidNavigationException e) { Assert.fail(e.getMessage()); } } Assert.assertTrue(8 == i); search = new TextNavigation("delete", doc); Assert.assertFalse(search.hasNext()); try { nextSelect.cut(); } catch (InvalidNavigationException e1) { Assert.fail(e1.getMessage()); } Assert.assertFalse(nextsearch.hasNext()); try { doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_DELETE)); } catch (Exception e) { Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }