From fd519471293b7706582c28640e06b064bc96558a Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 29 Sep 2018 18:45:18 +0100
Subject: [PATCH v1 1/4] SlippyMapBBoxChooser: correct check attempting to
 retain selection of TileSource when sources are refreshed

add a test for the MinimapDialog covering this
---
 .../openstreetmap/josm/gui/bbox/SourceButton.java  |  2 +-
 .../josm/gui/dialogs/MinimapDialogTest.java        | 37 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/org/openstreetmap/josm/gui/bbox/SourceButton.java b/src/org/openstreetmap/josm/gui/bbox/SourceButton.java
index d9236d6de..9a59d3e31 100644
--- a/src/org/openstreetmap/josm/gui/bbox/SourceButton.java
+++ b/src/org/openstreetmap/josm/gui/bbox/SourceButton.java
@@ -81,7 +81,7 @@ public class SourceButton extends PopupMenuButton {
             this.sourceButtonGroup.add(menuItem);
 
             // attempt to initialize button group matching current state of slippyMapBBoxChooser
-            buttonModel.setSelected(this.slippyMapBBoxChooser.getTileController().getTileSource() == ts);
+            buttonModel.setSelected(this.slippyMapBBoxChooser.getTileController().getTileSource().getId().equals(ts.getId()));
         }
 
         pm.addSeparator();
diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
index a5de69ba8..f8a61a41b 100644
--- a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
+++ b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
@@ -220,6 +220,43 @@ public class MinimapDialogTest {
     }
 
     /**
+     * Tests that the apparently-selected TileSource survives the tile sources being refreshed.
+     * @throws Exception if any error occurs
+     */
+    @Test
+    public void testRefreshSourcesRetainsSelection() throws Exception {
+        // relevant prefs starting out empty, should choose the first source and have shown download area enabled
+        // (not that there's a data layer for it to use)
+
+        this.setUpMiniMap();
+
+        this.clickSourceMenuItemByLabel("Magenta Tiles");
+        this.assertSingleSelectedSourceLabel("Magenta Tiles");
+
+        // call paint to trigger new tile fetch
+        this.paintSlippyMap();
+
+        Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished);
+
+        this.paintSlippyMap();
+
+        assertEquals(0xffff00ff, paintedSlippyMap.getRGB(0, 0));
+
+        this.slippyMap.refreshTileSources();
+
+        this.assertSingleSelectedSourceLabel("Magenta Tiles");
+
+        // call paint to trigger new tile fetch
+        this.paintSlippyMap();
+
+        Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished);
+
+        this.paintSlippyMap();
+
+        assertEquals(0xffff00ff, paintedSlippyMap.getRGB(0, 0));
+    }
+
+    /**
      * Tests minimap obeys a saved "mapstyle" preference on startup.
      * @throws Exception if any error occurs
      */
-- 
2.11.0

