diff --git a/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportSaveTest.java b/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportDoubleSaveTest.java copy from openide.text/test/unit/src/org/openide/text/CloneableEditorSupportSaveTest.java copy to openide.text/test/unit/src/org/openide/text/CloneableEditorSupportDoubleSaveTest.java --- a/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportSaveTest.java +++ b/openide.text/test/unit/src/org/openide/text/CloneableEditorSupportDoubleSaveTest.java @@ -54,7 +54,6 @@ import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import javax.swing.JEditorPane; import javax.swing.text.Document; import junit.framework.Test; import junit.framework.TestSuite; @@ -63,7 +62,6 @@ import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; -import org.openide.util.io.NbMarshalledObject; import org.openide.windows.CloneableOpenSupport; import org.openide.windows.CloneableTopComponent; @@ -71,11 +69,11 @@ * * @author Miloslav Metelka */ -public class CloneableEditorSupportSaveTest extends NbTestCase +public class CloneableEditorSupportDoubleSaveTest extends NbTestCase implements CloneableEditorSupport.Env { public static Test suite() { - return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(CloneableEditorSupportSaveTest.class); + return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(CloneableEditorSupportDoubleSaveTest.class); } static { @@ -98,9 +96,10 @@ private transient AtomicBoolean docModDuringSaveStream = new AtomicBoolean(); private transient AtomicBoolean saveDocumentFinished = new AtomicBoolean(); - private static CloneableEditorSupportSaveTest RUNNING; + private static CloneableEditorSupportDoubleSaveTest RUNNING; + private Thread letMeGo; - public CloneableEditorSupportSaveTest(String s) { + public CloneableEditorSupportDoubleSaveTest(String s) { super(s); } @@ -135,35 +134,19 @@ }); waitFor(saveToStreamStarted); - doc.insertString(1, "b", null); + + doc.insertString(1, "hoj", null); + letMeGo = Thread.currentThread(); + support.saveDocument(); docModDuringSaveStream.set(true); + waitFor(saveDocumentFinished); - // Here the document should be modified again since doc mod was made - assertTrue(isModified()); + + assertFalse("Document has been saved (for 2nd time)", isModified()); + + assertEquals("ahoj", content); } - public void testNormalSave() throws Exception { - Document doc = support.openDocument(); - doc.insertString(0, "a", null); - RequestProcessor.getDefault().post(new Runnable() { - @Override - public void run() { - try { - support.saveDocument(); - saveDocumentFinished.set(true); - } catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - }); - - waitFor(saveToStreamStarted); - docModDuringSaveStream.set(true); // In fact no modification occurred - waitFor(saveDocumentFinished); - assertFalse(isModified()); - } - - // // Implementation of the CloneableEditorSupport.Env // @@ -214,12 +197,13 @@ public void close () throws IOException { super.close (); content = new String (toByteArray ()); - } } - - saveToStreamStarted.set(true); - waitFor(docModDuringSaveStream); + + if (letMeGo != Thread.currentThread()) { + saveToStreamStarted.set(true); + waitFor(docModDuringSaveStream); + } return new ContentStream (); }