From 9044197eeff670bc7cc5e4d617478f55d11d346f Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Tue, 31 Oct 2017 22:08:40 +0000
Subject: [PATCH 3/4] JOSMTestRules: add fakeImagery() method(s) for setting up
a TileSourceRule as part of the mock JOSM setup process
---
.../josm/testutils/JOSMTestRules.java | 54 ++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index 238ed200e..22e9e95f7 100644
|
a
|
b
|
import java.security.GeneralSecurityException;
|
| 7 | 7 | import java.text.MessageFormat; |
| 8 | 8 | import java.util.TimeZone; |
| 9 | 9 | |
| | 10 | import java.awt.Color; |
| | 11 | |
| 10 | 12 | import org.junit.rules.TemporaryFolder; |
| 11 | 13 | import org.junit.rules.TestRule; |
| 12 | 14 | import org.junit.runner.Description; |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 56 | 58 | private boolean usePreferences = false; |
| 57 | 59 | private APIType useAPI = APIType.NONE; |
| 58 | 60 | private String i18n = null; |
| | 61 | private TileSourceRule tileSourceRule; |
| 59 | 62 | private boolean platform; |
| 60 | 63 | private boolean useProjection; |
| 61 | 64 | private boolean useProjectionNadGrids; |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 242 | 245 | } |
| 243 | 246 | |
| 244 | 247 | /** |
| | 248 | * Replace imagery sources with a default set of mock tile sources |
| | 249 | * |
| | 250 | * @return this instance, for easy chaining |
| | 251 | */ |
| | 252 | public JOSMTestRules fakeImagery() { |
| | 253 | return this.fakeImagery( |
| | 254 | new TileSourceRule( |
| | 255 | true, |
| | 256 | true, |
| | 257 | true, |
| | 258 | new TileSourceRule.ColorSource(Color.WHITE, "White Tiles", 256), |
| | 259 | new TileSourceRule.ColorSource(Color.BLACK, "Black Tiles", 256), |
| | 260 | new TileSourceRule.ColorSource(Color.MAGENTA, "Magenta Tiles", 256), |
| | 261 | new TileSourceRule.ColorSource(Color.GREEN, "Green Tiles", 256) |
| | 262 | ) |
| | 263 | ); |
| | 264 | } |
| | 265 | |
| | 266 | /** |
| | 267 | * Replace imagery sources with those from specific mock tile server setup |
| | 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. |
| 247 | 280 | * @return this instance, for easy chaining |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 256 | 289 | @Override |
| 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); |
| 266 | 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); |
| | 313 | } |
| 267 | 314 | return statement; |
| 268 | 315 | } |
| 269 | 316 | |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 409 | 456 | } |
| 410 | 457 | |
| 411 | 458 | /** |
| | 459 | * @return TileSourceRule which is automatically started by this rule |
| | 460 | */ |
| | 461 | public TileSourceRule getTileSourceRule() { |
| | 462 | return this.tileSourceRule; |
| | 463 | } |
| | 464 | |
| | 465 | /** |
| 412 | 466 | * Clean up after running a test |
| 413 | 467 | */ |
| 414 | 468 | @SuppressFBWarnings("DM_GC") |