diff options
author | Paul Duffin <paulduffin@google.com> | 2016-12-14 12:55:56 +0000 |
---|---|---|
committer | Pete Bentley <prb@google.com> | 2021-03-02 23:56:53 +0000 |
commit | 77cf67c410a013f5e33dc7b333a614f7e1b5ac66 (patch) | |
tree | 9c162afd814d4158644c5a6b564ae6b8788316bd | |
parent | 75dd2ceb505380a918bec2cb3d3096a6b362574c (diff) | |
download | junit-77cf67c410a013f5e33dc7b333a614f7e1b5ac66.tar.gz |
Remove DisableOnDebug (new in 4.12) as it is not supported on Android
It requires classes from the java.lang.management package which
is not supported on Android.
This change re-lands https://r.android.com/1601634
Bug: 129054170
Test: m
Change-Id: Id1e2d63892e25026f68f9a345d788e2e7497e737
(cherry picked from commit c8055484aac0d002d00140b789711414f4130428)
-rw-r--r-- | README.version | 1 | ||||
-rw-r--r-- | src/main/java/org/junit/rules/DisableOnDebug.java | 125 |
2 files changed, 1 insertions, 125 deletions
diff --git a/README.version b/README.version index e525ad8..74c20ad 100644 --- a/README.version +++ b/README.version @@ -4,3 +4,4 @@ BugComponent: 40416 Local Changes: Extra generic type information to aid certain javacs. + Remove DisableOnDebug (new in 4.12) as it is not supported on Android diff --git a/src/main/java/org/junit/rules/DisableOnDebug.java b/src/main/java/org/junit/rules/DisableOnDebug.java deleted file mode 100644 index 3bca103..0000000 --- a/src/main/java/org/junit/rules/DisableOnDebug.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.junit.rules; - -import java.util.List; - -import org.junit.internal.management.ManagementFactory; -import org.junit.internal.management.RuntimeMXBean; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * The {@code DisableOnDebug} Rule allows you to label certain rules to be - * disabled when debugging. - * <p> - * The most illustrative use case is for tests that make use of the - * {@link Timeout} rule, when ran in debug mode the test may terminate on - * timeout abruptly during debugging. Developers may disable the timeout, or - * increase the timeout by making a code change on tests that need debugging and - * remember revert the change afterwards or rules such as {@link Timeout} that - * may be disabled during debugging may be wrapped in a {@code DisableOnDebug}. - * <p> - * The important benefit of this feature is that you can disable such rules - * without any making any modifications to your test class to remove them during - * debugging. - * <p> - * This does nothing to tackle timeouts or time sensitive code under test when - * debugging and may make this less useful in such circumstances. - * <p> - * Example usage: - * - * <pre> - * public static class DisableTimeoutOnDebugSampleTest { - * - * @Rule - * public TestRule timeout = new DisableOnDebug(new Timeout(20)); - * - * @Test - * public void myTest() { - * int i = 0; - * assertEquals(0, i); // suppose you had a break point here to inspect i - * } - * } - * </pre> - * - * @since 4.12 - */ -public class DisableOnDebug implements TestRule { - private final TestRule rule; - private final boolean debugging; - - /** - * Create a {@code DisableOnDebug} instance with the timeout specified in - * milliseconds. - * - * @param rule to disable during debugging - */ - public DisableOnDebug(TestRule rule) { - this(rule, ManagementFactory.getRuntimeMXBean() - .getInputArguments()); - } - - /** - * Visible for testing purposes only. - * - * @param rule the rule to disable during debugging - * @param inputArguments - * arguments provided to the Java runtime - */ - DisableOnDebug(TestRule rule, List<String> inputArguments) { - this.rule = rule; - debugging = isDebugging(inputArguments); - } - - /** - * @see TestRule#apply(Statement, Description) - */ - public Statement apply(Statement base, Description description) { - if (debugging) { - return base; - } else { - return rule.apply(base, description); - } - } - - /** - * Parses arguments passed to the runtime environment for debug flags - * <p> - * Options specified in: - * <ul> - * <li> - * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/conninv.html#Invocation" - * >javase-6</a></li> - * <li><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html#Invocation" - * >javase-7</a></li> - * <li><a href="http://docs.oracle.com/javase/8/docs/technotes/guides/jpda/conninv.html#Invocation" - * >javase-8</a></li> - * - * - * @param arguments - * the arguments passed to the runtime environment, usually this - * will be {@link RuntimeMXBean#getInputArguments()} - * @return true if the current JVM was started in debug mode, false - * otherwise. - */ - private static boolean isDebugging(List<String> arguments) { - for (final String argument : arguments) { - if ("-Xdebug".equals(argument) || argument.startsWith("-agentlib:jdwp")) { - return true; - } - } - return false; - } - - /** - * Returns {@code true} if the JVM is in debug mode. This method may be used - * by test classes to take additional action to disable code paths that - * interfere with debugging if required. - * - * @return {@code true} if the current JVM is in debug mode, {@code false} - * otherwise - */ - public boolean isDebugging() { - return debugging; - } - -} |