samples/trycatchredo/test/org/apidesign/exceptions/trycatchredo/api/IOManagerTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 16:29:46 +0100
changeset 312 0678c9589013
child 411 9eb6379b97f0
permissions -rw-r--r--
Renaming the project to 'Try Catch Redo'
     1 package org.apidesign.exceptions.trycatchredo.api;
     2 
     3 
     4 import org.apidesign.exceptions.trycatchredo.usage.MemoryURL;
     5 import java.awt.EventQueue;
     6 import java.awt.event.ActionEvent;
     7 import java.net.URL;
     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.*;
    15 
    16 /**
    17  *
    18  * @author Jaroslav Tulach <jtulach@netbeans.org>
    19  */
    20 public class IOManagerTest {
    21 
    22     public IOManagerTest() {
    23     }
    24 
    25     @Before
    26     public void setUp() {
    27         MemoryURL.initialize();
    28     }
    29 
    30     @After
    31     public void tearDown() {
    32     }
    33 
    34     @Test
    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() {
    40             public void run() {
    41                 a.actionPerformed(new ActionEvent(this, 0, ""));
    42             }
    43         });
    44         String out = MemoryURL.getOutputForURL(u.toExternalForm());
    45         assertEquals("Hello World!", out);
    46     }
    47 
    48     @Test
    49     public void writeWithAQuestion() throws Exception {
    50         URL u = new URL("memory://queryEncoding.txt");
    51 
    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() {
    57             public void run() {
    58                 a.actionPerformed(new ActionEvent(this, 0, ""));
    59             }
    60         });
    61         String out = MemoryURL.getOutputForURL(u.toExternalForm());
    62         assertEquals("Text is reversed", "noitseuQ a ksA", out);
    63     }
    64 }