Lines 54-60
Link Here
|
54 |
import java.util.Date; |
54 |
import java.util.Date; |
55 |
import java.util.List; |
55 |
import java.util.List; |
56 |
import java.util.concurrent.atomic.AtomicBoolean; |
56 |
import java.util.concurrent.atomic.AtomicBoolean; |
57 |
import javax.swing.JEditorPane; |
|
|
58 |
import javax.swing.text.Document; |
57 |
import javax.swing.text.Document; |
59 |
import junit.framework.Test; |
58 |
import junit.framework.Test; |
60 |
import junit.framework.TestSuite; |
59 |
import junit.framework.TestSuite; |
Lines 63-69
Link Here
|
63 |
import org.openide.util.Exceptions; |
62 |
import org.openide.util.Exceptions; |
64 |
import org.openide.util.Lookup; |
63 |
import org.openide.util.Lookup; |
65 |
import org.openide.util.RequestProcessor; |
64 |
import org.openide.util.RequestProcessor; |
66 |
import org.openide.util.io.NbMarshalledObject; |
|
|
67 |
import org.openide.windows.CloneableOpenSupport; |
65 |
import org.openide.windows.CloneableOpenSupport; |
68 |
import org.openide.windows.CloneableTopComponent; |
66 |
import org.openide.windows.CloneableTopComponent; |
69 |
|
67 |
|
Lines 71-81
Link Here
|
71 |
* |
69 |
* |
72 |
* @author Miloslav Metelka |
70 |
* @author Miloslav Metelka |
73 |
*/ |
71 |
*/ |
74 |
public class CloneableEditorSupportSaveTest extends NbTestCase |
72 |
public class CloneableEditorSupportDoubleSaveTest extends NbTestCase |
75 |
implements CloneableEditorSupport.Env { |
73 |
implements CloneableEditorSupport.Env { |
76 |
|
74 |
|
77 |
public static Test suite() { |
75 |
public static Test suite() { |
78 |
return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(CloneableEditorSupportSaveTest.class); |
76 |
return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(CloneableEditorSupportDoubleSaveTest.class); |
79 |
} |
77 |
} |
80 |
|
78 |
|
81 |
static { |
79 |
static { |
Lines 98-106
Link Here
|
98 |
private transient AtomicBoolean docModDuringSaveStream = new AtomicBoolean(); |
96 |
private transient AtomicBoolean docModDuringSaveStream = new AtomicBoolean(); |
99 |
private transient AtomicBoolean saveDocumentFinished = new AtomicBoolean(); |
97 |
private transient AtomicBoolean saveDocumentFinished = new AtomicBoolean(); |
100 |
|
98 |
|
101 |
private static CloneableEditorSupportSaveTest RUNNING; |
99 |
private static CloneableEditorSupportDoubleSaveTest RUNNING; |
|
|
100 |
private Thread letMeGo; |
102 |
|
101 |
|
103 |
public CloneableEditorSupportSaveTest(String s) { |
102 |
public CloneableEditorSupportDoubleSaveTest(String s) { |
104 |
super(s); |
103 |
super(s); |
105 |
} |
104 |
} |
106 |
|
105 |
|
Lines 135-169
Link Here
|
135 |
}); |
134 |
}); |
136 |
|
135 |
|
137 |
waitFor(saveToStreamStarted); |
136 |
waitFor(saveToStreamStarted); |
138 |
doc.insertString(1, "b", null); |
137 |
|
|
|
138 |
doc.insertString(1, "hoj", null); |
139 |
letMeGo = Thread.currentThread(); |
140 |
support.saveDocument(); |
139 |
docModDuringSaveStream.set(true); |
141 |
docModDuringSaveStream.set(true); |
|
|
142 |
|
140 |
waitFor(saveDocumentFinished); |
143 |
waitFor(saveDocumentFinished); |
141 |
// Here the document should be modified again since doc mod was made |
144 |
|
142 |
assertTrue(isModified()); |
145 |
assertFalse("Document has been saved (for 2nd time)", isModified()); |
|
|
146 |
|
147 |
assertEquals("ahoj", content); |
143 |
} |
148 |
} |
144 |
|
149 |
|
145 |
public void testNormalSave() throws Exception { |
|
|
146 |
Document doc = support.openDocument(); |
147 |
doc.insertString(0, "a", null); |
148 |
RequestProcessor.getDefault().post(new Runnable() { |
149 |
@Override |
150 |
public void run() { |
151 |
try { |
152 |
support.saveDocument(); |
153 |
saveDocumentFinished.set(true); |
154 |
} catch (IOException ex) { |
155 |
throw new IllegalStateException(ex); |
156 |
} |
157 |
} |
158 |
}); |
159 |
|
160 |
waitFor(saveToStreamStarted); |
161 |
docModDuringSaveStream.set(true); // In fact no modification occurred |
162 |
waitFor(saveDocumentFinished); |
163 |
assertFalse(isModified()); |
164 |
} |
165 |
|
166 |
|
167 |
// |
150 |
// |
168 |
// Implementation of the CloneableEditorSupport.Env |
151 |
// Implementation of the CloneableEditorSupport.Env |
169 |
// |
152 |
// |
Lines 214-225
Link Here
|
214 |
public void close () throws IOException { |
197 |
public void close () throws IOException { |
215 |
super.close (); |
198 |
super.close (); |
216 |
content = new String (toByteArray ()); |
199 |
content = new String (toByteArray ()); |
217 |
|
|
|
218 |
} |
200 |
} |
219 |
} |
201 |
} |
220 |
|
202 |
|
221 |
saveToStreamStarted.set(true); |
203 |
if (letMeGo != Thread.currentThread()) { |
222 |
waitFor(docModDuringSaveStream); |
204 |
saveToStreamStarted.set(true); |
|
|
205 |
waitFor(docModDuringSaveStream); |
206 |
} |
223 |
return new ContentStream (); |
207 |
return new ContentStream (); |
224 |
} |
208 |
} |
225 |
|
209 |
|