Changeset 13078 in josm
- Timestamp:
- 2017-11-04T17:11:15+01:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r13011 r13078 22 22 <classpathentry kind="lib" path="test/lib/unitils-core/unitils-core-3.4.6.jar"/> 23 23 <classpathentry kind="lib" path="test/lib/commons-testing/commons-testing-2.1.0.jar"/> 24 <classpathentry kind="lib" path="test/lib/wiremock-standalone-2. 7.1.jar"/>24 <classpathentry kind="lib" path="test/lib/wiremock-standalone-2.10.1.jar"/> 25 25 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 26 26 <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/> -
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r12726 r13078 171 171 172 172 /** 173 * Returns a private static field value. 174 * @param cls object class 175 * @param fieldName private field name 176 * @return private field value 177 * @throws ReflectiveOperationException if a reflection operation error occurs 178 */ 179 public static Object getPrivateStaticField(Class<?> cls, String fieldName) throws ReflectiveOperationException { 180 Field f = cls.getDeclaredField(fieldName); 181 AccessController.doPrivileged((PrivilegedAction<Void>) () -> { 182 f.setAccessible(true); 183 return null; 184 }); 185 return f.get(null); 186 } 187 188 /** 173 189 * Returns an instance of {@link AbstractProgressMonitor} which keeps track of the monitor state, 174 190 * but does not show the progress. -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
r12564 r13078 2 2 package org.openstreetmap.josm.gui.dialogs; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertTrue; 7 import static org.junit.Assert.fail; 8 9 import java.awt.Color; 10 import java.awt.Component; 11 import java.awt.Graphics2D; 12 import java.awt.image.BufferedImage; 13 14 import javax.swing.JMenuItem; 15 import javax.swing.JPopupMenu; 6 16 7 17 import org.junit.Rule; 8 18 import org.junit.Test; 19 import org.openstreetmap.josm.TestUtils; 20 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 21 import org.openstreetmap.josm.gui.bbox.SourceButton; 9 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 23 … … 21 34 @Rule 22 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules test = new JOSMTestRules().platform();36 public JOSMTestRules josmTestRules = new JOSMTestRules().main().platform().projection().fakeImagery(); 24 37 25 38 /** … … 34 47 assertFalse(dlg.isVisible()); 35 48 } 49 50 private static void assertSingleSelectedSourceLabel(JPopupMenu menu, String label) { 51 boolean found = false; 52 for (Component c: menu.getComponents()) { 53 if (JPopupMenu.Separator.class.isInstance(c)) { 54 break; 55 } else { 56 boolean equalText = ((JMenuItem) c).getText() == label; 57 boolean isSelected = ((JMenuItem) c).isSelected(); 58 assertEquals(equalText, isSelected); 59 if (equalText) { 60 assertFalse("Second selected source found", found); 61 found = true; 62 } 63 } 64 } 65 assertTrue("Selected source not found in menu", found); 66 } 67 68 private static JMenuItem getSourceMenuItemByLabel(JPopupMenu menu, String label) { 69 for (Component c: menu.getComponents()) { 70 if (JPopupMenu.Separator.class.isInstance(c)) { 71 break; 72 } else if (((JMenuItem) c).getText() == label) { 73 return (JMenuItem) c; 74 } 75 // else continue... 76 } 77 fail("Failed to find menu item with label " + label); 78 return null; 79 } 80 81 /** 82 * Tests to switch imagery source. 83 * @throws Exception if any error occurs 84 */ 85 @Test 86 public void testSourceSwitching() throws Exception { 87 MinimapDialog dlg = new MinimapDialog(); 88 dlg.setSize(300, 200); 89 dlg.showDialog(); 90 SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap"); 91 SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton"); 92 93 // get dlg in a paintable state 94 dlg.addNotify(); 95 dlg.doLayout(); 96 97 BufferedImage image = new BufferedImage( 98 slippyMap.getSize().width, 99 slippyMap.getSize().height, 100 BufferedImage.TYPE_INT_RGB 101 ); 102 103 Graphics2D g = image.createGraphics(); 104 // an initial paint operation is required to trigger the tile fetches 105 slippyMap.paintAll(g); 106 g.setBackground(Color.BLUE); 107 g.clearRect(0, 0, image.getWidth(), image.getHeight()); 108 g.dispose(); 109 110 Thread.sleep(500); 111 112 g = image.createGraphics(); 113 slippyMap.paintAll(g); 114 115 assertEquals(0xffffffff, image.getRGB(0, 0)); 116 117 assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "White Tiles"); 118 119 getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); 120 assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Magenta Tiles"); 121 // call paint to trigger new tile fetch 122 slippyMap.paintAll(g); 123 124 // clear background to a recognizably "wrong" color & dispose our Graphics2D so we don't risk carrying over 125 // any state 126 g.setBackground(Color.BLUE); 127 g.clearRect(0, 0, image.getWidth(), image.getHeight()); 128 g.dispose(); 129 130 Thread.sleep(500); 131 132 g = image.createGraphics(); 133 slippyMap.paintAll(g); 134 135 assertEquals(0xffff00ff, image.getRGB(0, 0)); 136 137 getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Green Tiles").doClick(); 138 assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Green Tiles"); 139 // call paint to trigger new tile fetch 140 slippyMap.paintAll(g); 141 142 g.setBackground(Color.BLUE); 143 g.clearRect(0, 0, image.getWidth(), image.getHeight()); 144 g.dispose(); 145 146 Thread.sleep(500); 147 148 g = image.createGraphics(); 149 slippyMap.paintAll(g); 150 151 assertEquals(0xff00ff00, image.getRGB(0, 0)); 152 } 36 153 } -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r13021 r13078 2 2 package org.openstreetmap.josm.testutils; 3 3 4 import java.awt.Color; 4 5 import java.io.File; 5 6 import java.io.IOException; … … 57 58 private APIType useAPI = APIType.NONE; 58 59 private String i18n = null; 60 private TileSourceRule tileSourceRule; 59 61 private boolean platform; 60 62 private boolean useProjection; … … 243 245 244 246 /** 247 * Replace imagery sources with a default set of mock tile sources 248 * 249 * @return this instance, for easy chaining 250 */ 251 public JOSMTestRules fakeImagery() { 252 return this.fakeImagery( 253 new TileSourceRule( 254 true, 255 true, 256 true, 257 new TileSourceRule.ColorSource(Color.WHITE, "White Tiles", 256), 258 new TileSourceRule.ColorSource(Color.BLACK, "Black Tiles", 256), 259 new TileSourceRule.ColorSource(Color.MAGENTA, "Magenta Tiles", 256), 260 new TileSourceRule.ColorSource(Color.GREEN, "Green Tiles", 256) 261 ) 262 ); 263 } 264 265 /** 266 * Replace imagery sources with those from specific mock tile server setup 267 * @param tileSourceRule Tile source rule 268 * 269 * @return this instance, for easy chaining 270 */ 271 public JOSMTestRules fakeImagery(TileSourceRule tileSourceRule) { 272 this.preferences(); 273 this.tileSourceRule = tileSourceRule; 274 return this; 275 } 276 277 /** 245 278 * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel}, 246 279 * {@link Main#menu}, {@link Main#toolbar} global variables in this test. … … 257 290 public Statement apply(Statement base, Description description) { 258 291 Statement statement = base; 292 // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to 293 // be added into the chain *before* that one, so that it ends up on the "inside". 259 294 if (timeout > 0) { 260 295 // TODO: new DisableOnDebug(timeout) 261 296 statement = new FailOnTimeoutStatement(statement, timeout); 262 297 } 298 299 // this half of TileSourceRule's initialization must happen after josm is set up 300 if (this.tileSourceRule != null) { 301 statement = this.tileSourceRule.applyRegisterLayers(statement, description); 302 } 303 263 304 statement = new CreateJosmEnvironment(statement); 264 305 if (josmHome != null) { 265 306 statement = josmHome.apply(statement, description); 307 } 308 309 // run mock tile server as the outermost Statement (started first) so it can hopefully be initializing in 310 // parallel with other setup 311 if (this.tileSourceRule != null) { 312 statement = this.tileSourceRule.applyRunServer(statement, description); 266 313 } 267 314 return statement; … … 407 454 MainApplication.getLayerManager().resetState(); 408 455 eventManager.resetState(); 456 } 457 458 /** 459 * @return TileSourceRule which is automatically started by this rule 460 */ 461 public TileSourceRule getTileSourceRule() { 462 return this.tileSourceRule; 409 463 } 410 464
Note:
See TracChangeset
for help on using the changeset viewer.