Ignore:
Timestamp:
2018-08-31T03:00:20+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16700 - JOSMTestRules: give JOSMTestRules a mechanism to allow per-method overrides of rule options (patch by ris)

The caveats here are that it will only ever be possible to "add" additional options to the rule in the same way options can be appended to a call chain already (because they're processed using the same mechanism). Annotations can also only ever take primitive types as arguments (so no specifying new .fakeImagery(TileSourceRule ...) arguments)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r14201 r14207  
    88import java.io.File;
    99import java.io.IOException;
     10import java.lang.annotation.Documented;
     11import java.lang.annotation.ElementType;
     12import java.lang.annotation.Retention;
     13import java.lang.annotation.RetentionPolicy;
     14import java.lang.annotation.Target;
    1015import java.nio.charset.StandardCharsets;
    1116import java.security.GeneralSecurityException;
     
    148153
    149154    /**
    150      * Enable {@link Main#platform} global variable.
     155     * Enable {@code Main#platform} global variable.
    151156     * @return this instance, for easy chaining
    152157     * @deprecated Not needed anymore
     
    214219
    215220    /**
    216      * Allow the execution of commands using {@link Main#undoRedo}
     221     * Allow the execution of commands using {@code UndoRedoHandler}
    217222     * @return this instance, for easy chaining
    218223     */
     
    325330
    326331    /**
    327      * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
     332     * Use the {@code Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
    328333     *         global variables in this test.
    329334     * @return this instance, for easy chaining
     
    338343
    339344    /**
    340      * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
     345     * Use the {@code Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
    341346     *         global variables in this test.
    342347     * @param mapViewStateMockingRunnable Runnable to use for mocking out any required parts of
     
    368373    @Override
    369374    public Statement apply(Statement base, Description description) {
     375        // First process any Override* annotations for per-test overrides.
     376        // The following only work because "option" methods modify JOSMTestRules in-place
     377        final OverrideAssumeRevision overrideAssumeRevision = description.getAnnotation(OverrideAssumeRevision.class);
     378        if (overrideAssumeRevision != null) {
     379            this.assumeRevision(overrideAssumeRevision.value());
     380        }
     381        final OverrideTimeout overrideTimeout = description.getAnnotation(OverrideTimeout.class);
     382        if (overrideTimeout != null) {
     383            this.timeout(overrideTimeout.value());
     384        }
    370385        Statement statement = base;
    371386        // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to
     
    695710                getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
    696711    }
     712
     713    /**
     714     * Override this test's assumed JOSM version (as reported by {@link Version}).
     715     * @see JOSMTestRules#assumeRevision(String)
     716     */
     717    @Documented
     718    @Retention(RetentionPolicy.RUNTIME)
     719    @Target(ElementType.METHOD)
     720    public @interface OverrideAssumeRevision {
     721        /**
     722         * Returns overriden assumed JOSM version.
     723         * @return overriden assumed JOSM version
     724         */
     725        String value();
     726    }
     727
     728    /**
     729     * Override this test's timeout.
     730     * @see JOSMTestRules#timeout(int)
     731     */
     732    @Documented
     733    @Retention(RetentionPolicy.RUNTIME)
     734    @Target(ElementType.METHOD)
     735    public @interface OverrideTimeout {
     736        /**
     737         * Returns overriden timeout value.
     738         * @return overriden timeout value
     739         */
     740        int value();
     741    }
    697742}
Note: See TracChangeset for help on using the changeset viewer.