From a441a3d5445b926972ddb025796db8f55e8ef6bd Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Wed, 29 Aug 2018 20:06:40 +0100
Subject: [PATCH v1 1/2] JOSMTestRules: give JOSMTestRules a mechanism to allow
per-method overrides of rule options
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)
---
.../josm/testutils/JOSMTestRules.java | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index a425ec7f1..9fb529ba6 100644
|
a
|
b
|
import java.awt.event.WindowEvent;
|
| 7 | 7 | import java.io.ByteArrayInputStream; |
| 8 | 8 | import java.io.File; |
| 9 | 9 | import java.io.IOException; |
| | 10 | import java.lang.annotation.Documented; |
| | 11 | import java.lang.annotation.ElementType; |
| | 12 | import java.lang.annotation.Retention; |
| | 13 | import java.lang.annotation.RetentionPolicy; |
| | 14 | import java.lang.annotation.Target; |
| 10 | 15 | import java.nio.charset.StandardCharsets; |
| 11 | 16 | import java.security.GeneralSecurityException; |
| 12 | 17 | import java.text.MessageFormat; |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 367 | 372 | |
| 368 | 373 | @Override |
| 369 | 374 | 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 | } |
| | 385 | |
| 370 | 386 | Statement statement = base; |
| 371 | 387 | // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to |
| 372 | 388 | // be added into the chain *before* that one, so that it ends up on the "inside". |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 694 | 710 | return java.lang.management.ManagementFactory.getRuntimeMXBean(). |
| 695 | 711 | getInputArguments().toString().indexOf("-agentlib:jdwp") > 0; |
| 696 | 712 | } |
| | 713 | |
| | 714 | @Documented |
| | 715 | @Retention(RetentionPolicy.RUNTIME) |
| | 716 | @Target(ElementType.METHOD) |
| | 717 | public @interface OverrideAssumeRevision { |
| | 718 | String value(); |
| | 719 | } |
| | 720 | |
| | 721 | @Documented |
| | 722 | @Retention(RetentionPolicy.RUNTIME) |
| | 723 | @Target(ElementType.METHOD) |
| | 724 | public @interface OverrideTimeout { |
| | 725 | int value(); |
| | 726 | } |
| 697 | 727 | } |