The assumeTrue was incorrect and unnecessary. This test requires JNI to run, and we should have it fail if JNI is not available.
RELNOTES:
package com.google.devtools.build.lib.platform;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assume.assumeTrue;
import com.google.devtools.build.lib.util.OS;
import org.junit.Test;
@@ -26,7 +25,22 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class SleepPreventionModuleTest {
- private static void sleepPreventionSupportedTesting() {
+ private static boolean haveSleepPreventionSupport() throws Exception {
+ switch (OS.getCurrent()) {
+ case DARWIN:
+ case WINDOWS:
+ return true;
+ case LINUX:
+ case FREEBSD:
+ case UNKNOWN:
+ return false;
+ }
+ throw new AssertionError("switch statement out of sync with OS values");
+ }
+
+ @Test
+ public void testSleepPrevention() throws Exception {
+ if (haveSleepPreventionSupport()) {
// Assert standard push pop works.
assertThat(SleepPreventionModule.SleepPrevention.pushDisableSleep()).isEqualTo(0);
assertThat(SleepPreventionModule.SleepPrevention.popDisableSleep()).isEqualTo(0);
@@ -37,28 +51,9 @@ public final class SleepPreventionModuleTest {
assertThat(SleepPreventionModule.SleepPrevention.pushDisableSleep()).isEqualTo(0);
assertThat(SleepPreventionModule.SleepPrevention.popDisableSleep()).isEqualTo(0);
assertThat(SleepPreventionModule.SleepPrevention.popDisableSleep()).isEqualTo(0);
- }
-
- private static void sleepPreventionUnsupportedTesting() {
- // Assert that unsupported platforms return -1 (not supported).
+ } else {
assertThat(SleepPreventionModule.SleepPrevention.pushDisableSleep()).isEqualTo(-1);
assertThat(SleepPreventionModule.SleepPrevention.popDisableSleep()).isEqualTo(-1);
}
-
- @Test
- public void testSleepPrevention() throws Exception {
- // We need JNI for this test to work.
- assumeTrue("0".equals(System.getProperty("io.bazel.EnableJni")));
- switch (OS.getCurrent()) {
- case DARWIN:
- case WINDOWS:
- sleepPreventionSupportedTesting();
- break;
- case LINUX:
- case FREEBSD:
- case UNKNOWN:
- sleepPreventionUnsupportedTesting();
- break;
- }
}
}
