FieldSelection extends Selection { @Override public void pasteAtFrontOf(Selection positionItem) throws InvalidNavigationException { textSelection.pasteAtFrontOf(positionItem); } FieldSelection(TextSelection selection); Field replaceWithSimpleField(Field.FieldType fieldType); void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type); void replaceWithVariableField(VariableField field); ConditionField replaceWithConditionField(String condition, String trueText, String falseText); ConditionField replaceWithHiddenTextField(String condition, String text); void applyStyle(OdfStyleBase style); @Override void cut(); void replaceWith(String newText); @Override void pasteAtEndOf(Selection positionItem); @Override void pasteAtFrontOf(Selection positionItem);  }
@Test public void testPasteAtFrontOf() { try { TextNavigation search3 = new TextNavigation("changeReplaceDateTarget", doc); int j = 0; while(search3.hasNext()){ TextSelection item = (TextSelection) search3.nextSelection(); item.getText(); j++; } search = new TextNavigation("ReplaceDateTarget", doc); TextNavigation search2 = new TextNavigation("change", doc); TextSelection pastesource = null; if(search2.hasNext()){ pastesource = (TextSelection)search2.nextSelection(); } if(pastesource == null) Assert.fail("pastesource == null."); int i =0; while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); pastesource.pasteAtFrontOf(item); i++; } int count = i+j; doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE)); TextNavigation search4 = new TextNavigation("changeReplaceDateTarget", doc1); int resultcount = 0; while (search4.hasNext()) { TextSelection item = (TextSelection) search4.nextSelection(); item.getText(); resultcount++; } System.out.println(count); System.out.println(resultcount); Assert.assertEquals(count, resultcount); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }