From 5b4e9e328c84589d51ed06e48fb04385c8eb276e 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 | 52 ++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index 238ed200e..bf7b28414 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 | * |
| 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 | * |
| 267 | * @return this instance, for easy chaining |
| 268 | */ |
| 269 | public JOSMTestRules fakeImagery(TileSourceRule tileSourceRule) { |
| 270 | this.preferences(); |
| 271 | this.tileSourceRule = tileSourceRule; |
| 272 | return this; |
| 273 | } |
| 274 | |
| 275 | /** |
245 | 276 | * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel}, |
246 | 277 | * {@link Main#menu}, {@link Main#toolbar} global variables in this test. |
247 | 278 | * @return this instance, for easy chaining |
… |
… |
public class JOSMTestRules implements TestRule {
|
256 | 287 | @Override |
257 | 288 | public Statement apply(Statement base, Description description) { |
258 | 289 | Statement statement = base; |
| 290 | // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to |
| 291 | // be added into the chain *before* that one, so that it ends up on the "inside". |
259 | 292 | if (timeout > 0) { |
260 | 293 | // TODO: new DisableOnDebug(timeout) |
261 | 294 | statement = new FailOnTimeoutStatement(statement, timeout); |
262 | 295 | } |
| 296 | |
| 297 | // this half of TileSourceRule's initialization must happen after josm is set up |
| 298 | if (this.tileSourceRule != null) { |
| 299 | statement = this.tileSourceRule.applyRegisterLayers(statement, description); |
| 300 | } |
| 301 | |
263 | 302 | statement = new CreateJosmEnvironment(statement); |
264 | 303 | if (josmHome != null) { |
265 | 304 | statement = josmHome.apply(statement, description); |
266 | 305 | } |
| 306 | |
| 307 | // run mock tile server as the outermost Statement (started first) so it can hopefully be initializing in |
| 308 | // parallel with other setup |
| 309 | if (this.tileSourceRule != null) { |
| 310 | statement = this.tileSourceRule.applyRunServer(statement, description); |
| 311 | } |
267 | 312 | return statement; |
268 | 313 | } |
269 | 314 | |
… |
… |
public class JOSMTestRules implements TestRule {
|
409 | 454 | } |
410 | 455 | |
411 | 456 | /** |
| 457 | * @return TileSourceRule which is automatically started by this rule |
| 458 | */ |
| 459 | public TileSourceRule getTileSourceRule() { |
| 460 | return this.tileSourceRule; |
| 461 | } |
| 462 | |
| 463 | /** |
412 | 464 | * Clean up after running a test |
413 | 465 | */ |
414 | 466 | @SuppressFBWarnings("DM_GC") |