From 5e9a42471cdc9734fffb222b3137808753209a25 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 11 Nov 2017 12:15:38 +0000
Subject: [PATCH 2/6] MiniMapDialogTest: move minimap setup routine to shared
method
---
.../josm/gui/dialogs/MinimapDialogTest.java | 100 ++++++++++-----------
1 file changed, 46 insertions(+), 54 deletions(-)
diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
index 4c704bdae..ba4fafc53 100644
a
|
b
|
public class MinimapDialogTest {
|
79 | 79 | return null; |
80 | 80 | } |
81 | 81 | |
| 82 | protected MinimapDialog minimap; |
| 83 | protected SlippyMapBBoxChooser slippyMap; |
| 84 | protected SourceButton sourceButton; |
| 85 | |
| 86 | protected void setUpMiniMap() throws Exception { |
| 87 | this.minimap = new MinimapDialog(); |
| 88 | this.minimap.setSize(300, 200); |
| 89 | this.minimap.showDialog(); |
| 90 | this.slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(this.minimap, "slippyMap"); |
| 91 | this.sourceButton = (SourceButton) TestUtils.getPrivateField(this.slippyMap, "iSourceButton"); |
| 92 | |
| 93 | // get dlg in a paintable state |
| 94 | this.minimap.addNotify(); |
| 95 | this.minimap.doLayout(); |
| 96 | } |
| 97 | |
82 | 98 | /** |
83 | 99 | * Tests to switch imagery source. |
84 | 100 | * @throws Exception if any error occurs |
… |
… |
public class MinimapDialogTest {
|
88 | 104 | // relevant prefs starting out empty, should choose the first source and have shown download area enabled |
89 | 105 | // (not that there's a data layer for it to use) |
90 | 106 | |
91 | | MinimapDialog dlg = new MinimapDialog(); |
92 | | dlg.setSize(300, 200); |
93 | | dlg.showDialog(); |
94 | | SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap"); |
95 | | SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton"); |
96 | | |
97 | | // get dlg in a paintable state |
98 | | dlg.addNotify(); |
99 | | dlg.doLayout(); |
| 107 | this.setUpMiniMap(); |
100 | 108 | |
101 | 109 | BufferedImage image = new BufferedImage( |
102 | | slippyMap.getSize().width, |
103 | | slippyMap.getSize().height, |
| 110 | this.slippyMap.getSize().width, |
| 111 | this.slippyMap.getSize().height, |
104 | 112 | BufferedImage.TYPE_INT_RGB |
105 | 113 | ); |
106 | 114 | |
107 | 115 | Graphics2D g = image.createGraphics(); |
108 | 116 | // an initial paint operation is required to trigger the tile fetches |
109 | | slippyMap.paintAll(g); |
| 117 | this.slippyMap.paintAll(g); |
110 | 118 | g.setBackground(Color.BLUE); |
111 | 119 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
112 | 120 | g.dispose(); |
… |
… |
public class MinimapDialogTest {
|
114 | 122 | Thread.sleep(500); |
115 | 123 | |
116 | 124 | g = image.createGraphics(); |
117 | | slippyMap.paintAll(g); |
| 125 | this.slippyMap.paintAll(g); |
118 | 126 | |
119 | 127 | assertEquals(0xffffffff, image.getRGB(0, 0)); |
120 | 128 | |
121 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "White Tiles"); |
| 129 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "White Tiles"); |
122 | 130 | |
123 | | getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); |
124 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Magenta Tiles"); |
| 131 | getSourceMenuItemByLabel(this.sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); |
| 132 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "Magenta Tiles"); |
125 | 133 | // call paint to trigger new tile fetch |
126 | | slippyMap.paintAll(g); |
| 134 | this.slippyMap.paintAll(g); |
127 | 135 | |
128 | 136 | // clear background to a recognizably "wrong" color & dispose our Graphics2D so we don't risk carrying over |
129 | 137 | // any state |
… |
… |
public class MinimapDialogTest {
|
134 | 142 | Thread.sleep(500); |
135 | 143 | |
136 | 144 | g = image.createGraphics(); |
137 | | slippyMap.paintAll(g); |
| 145 | this.slippyMap.paintAll(g); |
138 | 146 | |
139 | 147 | assertEquals(0xffff00ff, image.getRGB(0, 0)); |
140 | 148 | |
141 | | getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Green Tiles").doClick(); |
142 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Green Tiles"); |
| 149 | getSourceMenuItemByLabel(this.sourceButton.getPopupMenu(), "Green Tiles").doClick(); |
| 150 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "Green Tiles"); |
143 | 151 | // call paint to trigger new tile fetch |
144 | | slippyMap.paintAll(g); |
| 152 | this.slippyMap.paintAll(g); |
145 | 153 | |
146 | 154 | g.setBackground(Color.BLUE); |
147 | 155 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
… |
… |
public class MinimapDialogTest {
|
150 | 158 | Thread.sleep(500); |
151 | 159 | |
152 | 160 | g = image.createGraphics(); |
153 | | slippyMap.paintAll(g); |
| 161 | this.slippyMap.paintAll(g); |
154 | 162 | |
155 | 163 | assertEquals(0xff00ff00, image.getRGB(0, 0)); |
156 | 164 | |
… |
… |
public class MinimapDialogTest {
|
158 | 166 | } |
159 | 167 | |
160 | 168 | @Test |
161 | | public void testSourcePrefObeyed() throws Throwable { |
| 169 | public void testSourcePrefObeyed() throws Exception { |
162 | 170 | Main.pref.put("slippy_map_chooser.mapstyle", "Green Tiles"); |
163 | 171 | |
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(); |
| 172 | this.setUpMiniMap(); |
173 | 173 | |
174 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Green Tiles"); |
| 174 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "Green Tiles"); |
175 | 175 | |
176 | 176 | BufferedImage image = new BufferedImage( |
177 | | slippyMap.getSize().width, |
178 | | slippyMap.getSize().height, |
| 177 | this.slippyMap.getSize().width, |
| 178 | this.slippyMap.getSize().height, |
179 | 179 | BufferedImage.TYPE_INT_RGB |
180 | 180 | ); |
181 | 181 | |
182 | 182 | Graphics2D g = image.createGraphics(); |
183 | 183 | // an initial paint operation is required to trigger the tile fetches |
184 | | slippyMap.paintAll(g); |
| 184 | this.slippyMap.paintAll(g); |
185 | 185 | g.setBackground(Color.BLUE); |
186 | 186 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
187 | 187 | g.dispose(); |
… |
… |
public class MinimapDialogTest {
|
189 | 189 | Thread.sleep(500); |
190 | 190 | |
191 | 191 | g = image.createGraphics(); |
192 | | slippyMap.paintAll(g); |
| 192 | this.slippyMap.paintAll(g); |
193 | 193 | |
194 | 194 | assertEquals(0xff00ff00, image.getRGB(0, 0)); |
195 | 195 | |
196 | | getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); |
197 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Magenta Tiles"); |
| 196 | getSourceMenuItemByLabel(this.sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); |
| 197 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "Magenta Tiles"); |
198 | 198 | |
199 | 199 | assertEquals("Magenta Tiles", Main.pref.get("slippy_map_chooser.mapstyle", "Fail")); |
200 | 200 | } |
201 | 201 | |
202 | 202 | @Test |
203 | | public void testSourcePrefInvalid() throws Throwable { |
| 203 | public void testSourcePrefInvalid() throws Exception { |
204 | 204 | Main.pref.put("slippy_map_chooser.mapstyle", "Hooloovoo Tiles"); |
205 | 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(); |
| 206 | this.setUpMiniMap(); |
215 | 207 | |
216 | | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "White Tiles"); |
| 208 | assertSingleSelectedSourceLabel(this.sourceButton.getPopupMenu(), "White Tiles"); |
217 | 209 | |
218 | 210 | BufferedImage image = new BufferedImage( |
219 | | slippyMap.getSize().width, |
220 | | slippyMap.getSize().height, |
| 211 | this.slippyMap.getSize().width, |
| 212 | this.slippyMap.getSize().height, |
221 | 213 | BufferedImage.TYPE_INT_RGB |
222 | 214 | ); |
223 | 215 | |
224 | 216 | Graphics2D g = image.createGraphics(); |
225 | 217 | // an initial paint operation is required to trigger the tile fetches |
226 | | slippyMap.paintAll(g); |
| 218 | this.slippyMap.paintAll(g); |
227 | 219 | g.setBackground(Color.BLUE); |
228 | 220 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
229 | 221 | g.dispose(); |
… |
… |
public class MinimapDialogTest {
|
231 | 223 | Thread.sleep(500); |
232 | 224 | |
233 | 225 | g = image.createGraphics(); |
234 | | slippyMap.paintAll(g); |
| 226 | this.slippyMap.paintAll(g); |
235 | 227 | |
236 | 228 | assertEquals(0xffffffff, image.getRGB(0, 0)); |
237 | 229 | } |