Ticket #15539: v1-0001-MinimapDialogTest-add-tests-for-pref-handling.patch

File v1-0001-MinimapDialogTest-add-tests-for-pref-handling.patch, 4.4 KB (added by ris, 8 years ago)
  • test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java

    From 06827d91cc5806ac8f89a977c0e4e23485238d6d Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 4 Nov 2017 11:29:25 +0000
    Subject: [PATCH 1/6] MinimapDialogTest: add tests for pref handling
    
    ---
     .../josm/gui/dialogs/MinimapDialogTest.java        | 85 ++++++++++++++++++++++
     1 file changed, 85 insertions(+)
    
    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
    index bce0cdfcd..4c704bdae 100644
    a b import javax.swing.JPopupMenu;  
    1616
    1717import org.junit.Rule;
    1818import org.junit.Test;
     19import org.openstreetmap.josm.Main;
    1920import org.openstreetmap.josm.TestUtils;
    2021import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    2122import org.openstreetmap.josm.gui.bbox.SourceButton;
    public class MinimapDialogTest {  
    8485     */
    8586    @Test
    8687    public void testSourceSwitching() throws Exception {
     88        // relevant prefs starting out empty, should choose the first source and have shown download area enabled
     89        // (not that there's a data layer for it to use)
     90
    8791        MinimapDialog dlg = new MinimapDialog();
    8892        dlg.setSize(300, 200);
    8993        dlg.showDialog();
    public class MinimapDialogTest {  
    149153        slippyMap.paintAll(g);
    150154
    151155        assertEquals(0xff00ff00, image.getRGB(0, 0));
     156
     157        assertEquals("Green Tiles", Main.pref.get("slippy_map_chooser.mapstyle", "Fail"));
     158    }
     159
     160    @Test
     161    public void testSourcePrefObeyed() throws Throwable {
     162        Main.pref.put("slippy_map_chooser.mapstyle", "Green Tiles");
     163
     164        MinimapDialog dlg = new MinimapDialog();
     165        dlg.setSize(300, 200);
     166        dlg.showDialog();
     167        SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap");
     168        SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton");
     169
     170        // get dlg in a paintable state
     171        dlg.addNotify();
     172        dlg.doLayout();
     173
     174        assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Green Tiles");
     175
     176        BufferedImage image = new BufferedImage(
     177            slippyMap.getSize().width,
     178            slippyMap.getSize().height,
     179            BufferedImage.TYPE_INT_RGB
     180        );
     181
     182        Graphics2D g = image.createGraphics();
     183        // an initial paint operation is required to trigger the tile fetches
     184        slippyMap.paintAll(g);
     185        g.setBackground(Color.BLUE);
     186        g.clearRect(0, 0, image.getWidth(), image.getHeight());
     187        g.dispose();
     188
     189        Thread.sleep(500);
     190
     191        g = image.createGraphics();
     192        slippyMap.paintAll(g);
     193
     194        assertEquals(0xff00ff00, image.getRGB(0, 0));
     195
     196        getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Magenta Tiles").doClick();
     197        assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Magenta Tiles");
     198
     199        assertEquals("Magenta Tiles", Main.pref.get("slippy_map_chooser.mapstyle", "Fail"));
     200    }
     201
     202    @Test
     203    public void testSourcePrefInvalid() throws Throwable {
     204        Main.pref.put("slippy_map_chooser.mapstyle", "Hooloovoo Tiles");
     205
     206        MinimapDialog dlg = new MinimapDialog();
     207        dlg.setSize(300, 200);
     208        dlg.showDialog();
     209        SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap");
     210        SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton");
     211
     212        // get dlg in a paintable state
     213        dlg.addNotify();
     214        dlg.doLayout();
     215
     216        assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "White Tiles");
     217
     218        BufferedImage image = new BufferedImage(
     219            slippyMap.getSize().width,
     220            slippyMap.getSize().height,
     221            BufferedImage.TYPE_INT_RGB
     222        );
     223
     224        Graphics2D g = image.createGraphics();
     225        // an initial paint operation is required to trigger the tile fetches
     226        slippyMap.paintAll(g);
     227        g.setBackground(Color.BLUE);
     228        g.clearRect(0, 0, image.getWidth(), image.getHeight());
     229        g.dispose();
     230
     231        Thread.sleep(500);
     232
     233        g = image.createGraphics();
     234        slippyMap.paintAll(g);
     235
     236        assertEquals(0xffffffff, image.getRGB(0, 0));
    152237    }
    153238}