jtulach@312
|
1 |
package org.apidesign.exceptions.trycatchredo.api;
|
jtulach@312
|
2 |
|
jtulach@312
|
3 |
|
jtulach@312
|
4 |
import org.apidesign.exceptions.trycatchredo.usage.MemoryURL;
|
jtulach@312
|
5 |
import java.awt.EventQueue;
|
jtulach@312
|
6 |
import java.awt.event.ActionEvent;
|
jtulach@312
|
7 |
import java.net.URL;
|
jtulach@312
|
8 |
import javax.swing.Action;
|
jtulach@312
|
9 |
import javax.swing.JOptionPane;
|
jtulach@312
|
10 |
import org.apidesign.exceptions.trycatchredo.usage.QueryStream;
|
jtulach@312
|
11 |
import org.junit.After;
|
jtulach@312
|
12 |
import org.junit.Before;
|
jtulach@312
|
13 |
import org.junit.Test;
|
jtulach@312
|
14 |
import static org.junit.Assert.*;
|
jtulach@312
|
15 |
|
jtulach@312
|
16 |
/**
|
jtulach@312
|
17 |
*
|
jtulach@312
|
18 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jtulach@312
|
19 |
*/
|
jtulach@312
|
20 |
public class IOManagerTest {
|
jtulach@312
|
21 |
|
jtulach@312
|
22 |
public IOManagerTest() {
|
jtulach@312
|
23 |
}
|
jtulach@312
|
24 |
|
jtulach@312
|
25 |
@Before
|
jtulach@312
|
26 |
public void setUp() {
|
jtulach@312
|
27 |
MemoryURL.initialize();
|
jtulach@312
|
28 |
}
|
jtulach@312
|
29 |
|
jtulach@312
|
30 |
@After
|
jtulach@312
|
31 |
public void tearDown() {
|
jtulach@312
|
32 |
}
|
jtulach@312
|
33 |
|
jtulach@312
|
34 |
@Test
|
jtulach@312
|
35 |
public void simpleWrite() throws Exception {
|
jtulach@312
|
36 |
URL u = new URL("memory://simpleWrite.txt");
|
jtulach@312
|
37 |
MemoryURL.registerURL(u.toExternalForm(), "", null);
|
jtulach@312
|
38 |
final Action a = IOManager.createSaveAction(u, "Hello World!");
|
jtulach@312
|
39 |
EventQueue.invokeAndWait(new Runnable() {
|
jtulach@312
|
40 |
public void run() {
|
jtulach@312
|
41 |
a.actionPerformed(new ActionEvent(this, 0, ""));
|
jtulach@312
|
42 |
}
|
jtulach@312
|
43 |
});
|
jtulach@312
|
44 |
String out = MemoryURL.getOutputForURL(u.toExternalForm());
|
jtulach@312
|
45 |
assertEquals("Hello World!", out);
|
jtulach@312
|
46 |
}
|
jtulach@312
|
47 |
|
jtulach@312
|
48 |
@Test
|
jtulach@312
|
49 |
public void writeWithAQuestion() throws Exception {
|
jtulach@312
|
50 |
URL u = new URL("memory://queryEncoding.txt");
|
jtulach@312
|
51 |
|
jtulach@312
|
52 |
MemoryURL.registerURL(u.toExternalForm(), "", new QueryStream());
|
jtulach@312
|
53 |
final Action a = IOManager.createSaveAction(u, "Ask a Question");
|
jtulach@312
|
54 |
// simulate that the user clicks Yes to the reverse question in the dialog
|
jtulach@312
|
55 |
IOManager.setVisibleOption = JOptionPane.YES_OPTION;
|
jtulach@312
|
56 |
EventQueue.invokeAndWait(new Runnable() {
|
jtulach@312
|
57 |
public void run() {
|
jtulach@312
|
58 |
a.actionPerformed(new ActionEvent(this, 0, ""));
|
jtulach@312
|
59 |
}
|
jtulach@312
|
60 |
});
|
jtulach@312
|
61 |
String out = MemoryURL.getOutputForURL(u.toExternalForm());
|
jtulach@312
|
62 |
assertEquals("Text is reversed", "noitseuQ a ksA", out);
|
jtulach@312
|
63 |
}
|
jtulach@312
|
64 |
} |