samples/exceptions/test/org/apidesign/exceptions/trycatchredo/api/IOManagerTest.java
1 package org.apidesign.exceptions.trycatchredo.api;
4 import org.apidesign.exceptions.trycatchredo.usage.MemoryURL;
5 import java.awt.EventQueue;
6 import java.awt.event.ActionEvent;
8 import javax.swing.Action;
9 import javax.swing.JOptionPane;
10 import org.apidesign.exceptions.trycatchredo.usage.QueryStream;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Test;
14 import static org.junit.Assert.*;
18 * @author Jaroslav Tulach <jtulach@netbeans.org>
20 public class IOManagerTest {
22 public IOManagerTest() {
27 MemoryURL.initialize();
31 public void tearDown() {
35 public void simpleWrite() throws Exception {
36 URL u = new URL("memory://simpleWrite.txt");
37 MemoryURL.registerURL(u.toExternalForm(), "", null);
38 final Action a = IOManager.createSaveAction(u, "Hello World!");
39 EventQueue.invokeAndWait(new Runnable() {
41 a.actionPerformed(new ActionEvent(this, 0, ""));
44 String out = MemoryURL.getOutputForURL(u.toExternalForm());
45 assertEquals("Hello World!", out);
49 public void writeWithAQuestion() throws Exception {
50 URL u = new URL("memory://queryEncoding.txt");
52 MemoryURL.registerURL(u.toExternalForm(), "", new QueryStream());
53 final Action a = IOManager.createSaveAction(u, "Ask a Question");
54 // simulate that the user clicks Yes to the reverse question in the dialog
55 IOManager.setVisibleOption = JOptionPane.YES_OPTION;
56 EventQueue.invokeAndWait(new Runnable() {
58 a.actionPerformed(new ActionEvent(this, 0, ""));
61 String out = MemoryURL.getOutputForURL(u.toExternalForm());
62 assertEquals("Text is reversed", "noitseuQ a ksA", out);