samples/trycatchredo/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 javax.swing.UIManager;
11 import javax.swing.UnsupportedLookAndFeelException;
12 import javax.swing.plaf.metal.MetalLookAndFeel;
13 import org.apidesign.exceptions.trycatchredo.usage.QueryStream;
14 import org.junit.After;
15 import org.junit.Before;
16 import org.junit.Test;
17 import static org.junit.Assert.*;
18 import org.junit.BeforeClass;
22 * @author Jaroslav Tulach <jtulach@netbeans.org>
24 public class IOManagerTest {
26 public IOManagerTest() {
30 public static void useMetalLaF() throws UnsupportedLookAndFeelException {
31 UIManager.setLookAndFeel(new MetalLookAndFeel());
36 MemoryURL.initialize();
40 public void tearDown() {
44 public void simpleWrite() throws Exception {
45 URL u = new URL("memory://simpleWrite.txt");
46 MemoryURL.registerURL(u.toExternalForm(), "", null);
47 final Action a = IOManager.createSaveAction(u, "Hello World!");
48 EventQueue.invokeAndWait(new Runnable() {
50 a.actionPerformed(new ActionEvent(this, 0, ""));
53 String out = MemoryURL.getOutputForURL(u.toExternalForm());
54 assertEquals("Hello World!", out);
58 public void writeWithAQuestion() throws Exception {
59 URL u = new URL("memory://queryEncoding.txt");
61 MemoryURL.registerURL(u.toExternalForm(), "", new QueryStream());
62 final Action a = IOManager.createSaveAction(u, "Ask a Question");
63 // simulate that the user clicks Yes to the reverse question in the dialog
64 IOManager.setVisibleOption = JOptionPane.YES_OPTION;
65 EventQueue.invokeAndWait(new Runnable() {
67 a.actionPerformed(new ActionEvent(this, 0, ""));
70 String out = MemoryURL.getOutputForURL(u.toExternalForm());
71 assertEquals("Text is reversed", "noitseuQ a ksA", out);