Ticket #15508: v1-0003-JOSMTestRules-add-fakeImagery-method-s-for-setting-u.patch

File v1-0003-JOSMTestRules-add-fakeImagery-method-s-for-setting-u.patch, 4.1 KB (added by ris, 7 years ago)
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    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;  
    77import java.text.MessageFormat;
    88import java.util.TimeZone;
    99
     10import java.awt.Color;
     11
    1012import org.junit.rules.TemporaryFolder;
    1113import org.junit.rules.TestRule;
    1214import org.junit.runner.Description;
    public class JOSMTestRules implements TestRule {  
    5658    private boolean usePreferences = false;
    5759    private APIType useAPI = APIType.NONE;
    5860    private String i18n = null;
     61    private TileSourceRule tileSourceRule;
    5962    private boolean platform;
    6063    private boolean useProjection;
    6164    private boolean useProjectionNadGrids;
    public class JOSMTestRules implements TestRule {  
    242245    }
    243246
    244247    /**
     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    /**
    245276     * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
    246277     *         {@link Main#menu}, {@link Main#toolbar} global variables in this test.
    247278     * @return this instance, for easy chaining
    public class JOSMTestRules implements TestRule {  
    256287    @Override
    257288    public Statement apply(Statement base, Description description) {
    258289        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".
    259292        if (timeout > 0) {
    260293            // TODO: new DisableOnDebug(timeout)
    261294            statement = new FailOnTimeoutStatement(statement, timeout);
    262295        }
     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
    263302        statement = new CreateJosmEnvironment(statement);
    264303        if (josmHome != null) {
    265304            statement = josmHome.apply(statement, description);
    266305        }
     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        }
    267312        return statement;
    268313    }
    269314
    public class JOSMTestRules implements TestRule {  
    409454    }
    410455
    411456    /**
     457     * @return TileSourceRule which is automatically started by this rule
     458     */
     459    public TileSourceRule getTileSourceRule() {
     460        return this.tileSourceRule;
     461    }
     462
     463    /**
    412464     * Clean up after running a test
    413465     */
    414466    @SuppressFBWarnings("DM_GC")