Changeset 12639 in josm for trunk/test/unit


Ignore:
Timestamp:
2017-08-25T01:37:31+02:00 (2 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate shortcut handling and mapframe listener methods in Main. Replacement: same methods in gui.MainApplication

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r12637 r12639  
    66import static org.junit.Assert.fail;
    77
    8 import java.awt.BorderLayout;
    98import java.io.File;
    109import java.io.IOException;
     
    1514import java.util.TimeZone;
    1615
    17 import javax.swing.JPanel;
    18 
    1916import org.openstreetmap.josm.data.projection.Projections;
    2017import org.openstreetmap.josm.gui.MainApplication;
    2118import org.openstreetmap.josm.gui.MainApplicationTest;
    22 import org.openstreetmap.josm.gui.MainPanel;
    2319import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer;
    2420import org.openstreetmap.josm.gui.util.GuiHelper;
     
    158154            if (Main.main.panel == null) {
    159155                initMainPanel(false);
    160                 Main.main.panel = Main.mainPanel;
     156                Main.main.panel = MainApplicationTest.getMainPanel();
    161157            }
    162158            Main.main.panel.reAddListeners();
     
    167163
    168164    /**
    169      * Make sure {@code Main.contentPanePrivate} is initialized.
     165     * Make sure {@code MainApplication.contentPanePrivate} is initialized.
    170166     */
    171167    public static void initContentPane() {
    172         if (Main.contentPanePrivate == null) {
    173             Main.contentPanePrivate = new JPanel(new BorderLayout());
    174         }
     168        MainApplicationTest.initContentPane();
    175169    }
    176170
    177171    /**
    178      * Make sure {@code Main.mainPanel} is initialized.
     172     * Make sure {@code MainApplication.mainPanel} is initialized.
    179173     */
    180174    public static void initMainPanel() {
     
    183177
    184178    /**
    185      * Make sure {@code Main.mainPanel} is initialized.
     179     * Make sure {@code MainApplication.mainPanel} is initialized.
    186180     * @param reAddListeners {@code true} to re-add listeners
    187181     */
    188182    public static void initMainPanel(boolean reAddListeners) {
    189         if (Main.mainPanel == null) {
    190             Main.mainPanel = new MainPanel(MainApplication.getLayerManager());
    191         }
    192         if (reAddListeners) {
    193             Main.mainPanel.reAddListeners();
    194         }
    195         if (Main.main != null) {
    196             Main.main.panel = Main.mainPanel;
    197         }
     183        MainApplicationTest.initMainPanel(reAddListeners);
    198184    }
    199185
    200186    /**
    201      * Make sure {@code Main.toolbar} is initialized.
     187     * Make sure {@code MainApplication.toolbar} is initialized.
    202188     */
    203     @SuppressWarnings("deprecation")
    204189    public static void initToolbar() {
    205190        MainApplicationTest.initToolbar();
    206         if (Main.toolbar == null) {
    207             Main.toolbar = MainApplication.getToolbar();
    208         }
    209191    }
    210192}
  • trunk/test/unit/org/openstreetmap/josm/MainTest.java

    r12637 r12639  
    88import static org.junit.Assert.assertTrue;
    99
    10 import java.awt.event.KeyEvent;
    1110import java.net.MalformedURLException;
    1211import java.net.URL;
     
    1817import org.openstreetmap.josm.Main.InitStatusListener;
    1918import org.openstreetmap.josm.Main.InitializationTask;
    20 import org.openstreetmap.josm.actions.AboutAction;
    21 import org.openstreetmap.josm.gui.MapFrameListener;
    2219import org.openstreetmap.josm.io.OnlineResource;
    2320import org.openstreetmap.josm.testutils.JOSMTestRules;
    24 import org.openstreetmap.josm.tools.Shortcut;
    2521
    2622import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    125121    }
    126122
    127     /**
    128      * Unit test of {@link Main#getRegisteredActionShortcut}.
    129      */
    130     @Test
    131     public void testGetRegisteredActionShortcut() {
    132         Shortcut noKeystroke = Shortcut.registerShortcut("no", "keystroke", 0, 0);
    133         assertNull(noKeystroke.getKeyStroke());
    134         assertNull(Main.getRegisteredActionShortcut(noKeystroke));
    135         Shortcut noAction = Shortcut.registerShortcut("foo", "bar", KeyEvent.VK_AMPERSAND, Shortcut.SHIFT);
    136         assertNotNull(noAction.getKeyStroke());
    137         assertNull(Main.getRegisteredActionShortcut(noAction));
    138         AboutAction about = new AboutAction();
    139         assertEquals(about, Main.getRegisteredActionShortcut(about.getShortcut()));
    140     }
    141 
    142     /**
    143      * Unit test of {@link Main#addMapFrameListener} and {@link Main#removeMapFrameListener}.
    144      */
    145     @Test
    146     public void testMapFrameListener() {
    147         MapFrameListener listener = (o, n) -> { };
    148         assertTrue(Main.addMapFrameListener(listener));
    149         assertFalse(Main.addMapFrameListener(null));
    150         assertTrue(Main.removeMapFrameListener(listener));
    151         assertFalse(Main.removeMapFrameListener(null));
    152     }
    153 
    154123    private static class InitStatusListenerStub implements InitStatusListener {
    155124
  • trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java

    r12637 r12639  
    66import static org.junit.Assert.assertNotNull;
    77import static org.junit.Assert.assertNull;
    8 
     8import static org.junit.Assert.assertTrue;
     9
     10import java.awt.BorderLayout;
     11import java.awt.event.KeyEvent;
    912import java.io.ByteArrayOutputStream;
    1013import java.io.IOException;
     
    1922import java.util.concurrent.Future;
    2023
     24import javax.swing.JComponent;
     25import javax.swing.JPanel;
    2126import javax.swing.UIManager;
    2227
     
    2530import org.openstreetmap.josm.Main;
    2631import org.openstreetmap.josm.TestUtils;
     32import org.openstreetmap.josm.actions.AboutAction;
    2733import org.openstreetmap.josm.data.Version;
    2834import org.openstreetmap.josm.data.osm.DataSet;
     
    3743import org.openstreetmap.josm.testutils.JOSMTestRules;
    3844import org.openstreetmap.josm.tools.Logging;
     45import org.openstreetmap.josm.tools.Shortcut;
    3946
    4047import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5360
    5461    /**
     62     * Make sure {@link MainApplication#contentPanePrivate} is initialized.
     63     */
     64    public static void initContentPane() {
     65        if (MainApplication.contentPanePrivate == null) {
     66            MainApplication.contentPanePrivate = new JPanel(new BorderLayout());
     67        }
     68    }
     69
     70    /**
     71     * Returns {@link MainApplication#contentPanePrivate} (not public).
     72     * @return {@link MainApplication#contentPanePrivate}
     73     */
     74    public static JComponent getContentPane() {
     75        return MainApplication.contentPanePrivate;
     76    }
     77
     78    /**
     79     * Make sure {@code MainApplication.mainPanel} is initialized.
     80     * @param reAddListeners {@code true} to re-add listeners
     81     */
     82    public static void initMainPanel(boolean reAddListeners) {
     83        if (MainApplication.mainPanel == null) {
     84            MainApplication.mainPanel = new MainPanel(MainApplication.getLayerManager());
     85        }
     86        if (reAddListeners) {
     87            MainApplication.mainPanel.reAddListeners();
     88        }
     89        if (Main.main != null) {
     90            Main.main.panel = MainApplication.mainPanel;
     91        }
     92    }
     93
     94    /**
     95     * Returns {@link MainApplication#mainPanel} (not public).
     96     * @return {@link MainApplication#mainPanel}
     97     */
     98    public static MainPanel getMainPanel() {
     99        return MainApplication.mainPanel;
     100    }
     101
     102    /**
    55103     * Make sure {@link MainApplication#toolbar} is initialized.
    56104     */
     105    @SuppressWarnings("deprecation")
    57106    public static void initToolbar() {
    58107        if (MainApplication.toolbar == null) {
    59108            MainApplication.toolbar = new ToolbarPreferences();
     109        }
     110        if (Main.toolbar == null) {
     111            Main.toolbar = MainApplication.getToolbar();
    60112        }
    61113    }
     
    236288
    237289    /**
     290     * Unit test of {@link MainApplication#getRegisteredActionShortcut}.
     291     */
     292    @Test
     293    public void testGetRegisteredActionShortcut() {
     294        Shortcut noKeystroke = Shortcut.registerShortcut("no", "keystroke", 0, 0);
     295        assertNull(noKeystroke.getKeyStroke());
     296        assertNull(MainApplication.getRegisteredActionShortcut(noKeystroke));
     297        Shortcut noAction = Shortcut.registerShortcut("foo", "bar", KeyEvent.VK_AMPERSAND, Shortcut.SHIFT);
     298        assertNotNull(noAction.getKeyStroke());
     299        assertNull(MainApplication.getRegisteredActionShortcut(noAction));
     300        AboutAction about = new AboutAction();
     301        assertEquals(about, MainApplication.getRegisteredActionShortcut(about.getShortcut()));
     302    }
     303
     304    /**
     305     * Unit test of {@link MainApplication#addMapFrameListener} and {@link MainApplication#removeMapFrameListener}.
     306     */
     307    @Test
     308    public void testMapFrameListener() {
     309        MapFrameListener listener = (o, n) -> { };
     310        assertTrue(MainApplication.addMapFrameListener(listener));
     311        assertFalse(MainApplication.addMapFrameListener(null));
     312        assertTrue(MainApplication.removeMapFrameListener(listener));
     313        assertFalse(MainApplication.removeMapFrameListener(null));
     314    }
     315
     316    /**
    238317     * Unit test of {@link DownloadParamType} enum.
    239318     */
Note: See TracChangeset for help on using the changeset viewer.