Automatic cleanup change.

PiperOrigin-RevId: 246010270
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
index b8a735d..d0b235d 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
@@ -17,7 +17,7 @@
 import static com.google.common.truth.Truth.assertWithMessage;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ARTIFACT_OWNER;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -229,14 +229,15 @@
     actionGraph.registerAction(originalAction);
 
     // Creating a second Action referring to the Artifact should create a conflict.
-    try {
-      Action action = new ActionsTestUtil.NullAction(NULL_ACTION_OWNER, a, b);
-      actionGraph.registerAction(action);
-      fail();
-    } catch (ActionConflictException e) {
-      assertThat(e.getArtifact()).isSameAs(a);
-      assertThat(actionGraph.getGeneratingAction(a)).isSameAs(originalAction);
-    }
+    Action action = new ActionsTestUtil.NullAction(NULL_ACTION_OWNER, a, b);
+    ActionConflictException e =
+        assertThrows(
+            ActionConflictException.class,
+            () -> {
+              actionGraph.registerAction(action);
+            });
+    assertThat(e.getArtifact()).isSameAs(a);
+    assertThat(actionGraph.getGeneratingAction(a)).isSameAs(originalAction);
   }
 
   private static class MockPackageRootResolver implements PackageRootResolver {
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java
index 5d36934..f486ba9 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.actions;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.testing.EqualsTester;
 import com.google.devtools.build.lib.testutil.Scratch;
@@ -43,11 +43,7 @@
 
   @Test
   public void testBadAsSourceRoot() {
-    try {
-      ArtifactRoot.asSourceRoot(null);
-      fail();
-    } catch (NullPointerException expected) {
-    }
+    assertThrows(NullPointerException.class, () -> ArtifactRoot.asSourceRoot(null));
   }
 
   @Test
@@ -63,43 +59,29 @@
 
   @Test
   public void testBadAsDerivedRoot() throws IOException {
-    try {
-      Path execRoot = scratch.dir("/exec");
-      Path outsideDir = scratch.dir("/not_exec");
-      ArtifactRoot.asDerivedRoot(execRoot, outsideDir);
-      fail();
-    } catch (IllegalArgumentException expected) {
-    }
+    Path execRoot = scratch.dir("/exec");
+    Path outsideDir = scratch.dir("/not_exec");
+    assertThrows(
+        IllegalArgumentException.class, () -> ArtifactRoot.asDerivedRoot(execRoot, outsideDir));
   }
 
   @Test
   public void testBadAsDerivedRootSameForBoth() throws IOException {
-    try {
-      Path execRoot = scratch.dir("/exec");
-      ArtifactRoot.asDerivedRoot(execRoot, execRoot);
-      fail();
-    } catch (IllegalArgumentException expected) {
-    }
+    Path execRoot = scratch.dir("/exec");
+    assertThrows(
+        IllegalArgumentException.class, () -> ArtifactRoot.asDerivedRoot(execRoot, execRoot));
   }
 
   @Test
   public void testBadAsDerivedRootNullDir() throws IOException {
-    try {
-      Path execRoot = scratch.dir("/exec");
-      ArtifactRoot.asDerivedRoot(execRoot, null);
-      fail();
-    } catch (NullPointerException expected) {
-    }
+    Path execRoot = scratch.dir("/exec");
+    assertThrows(NullPointerException.class, () -> ArtifactRoot.asDerivedRoot(execRoot, null));
   }
 
   @Test
   public void testBadAsDerivedRootNullExecRoot() throws IOException {
-    try {
-      Path execRoot = scratch.dir("/exec");
-      ArtifactRoot.asDerivedRoot(null, execRoot);
-      fail();
-    } catch (NullPointerException expected) {
-    }
+    Path execRoot = scratch.dir("/exec");
+    assertThrows(NullPointerException.class, () -> ArtifactRoot.asDerivedRoot(null, execRoot));
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
index 8aad11d..cc3587e 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.actions;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -64,10 +64,9 @@
   public void testConstruction_badRootDir() throws IOException {
     Path f1 = scratch.file("/exec/dir/file.ext");
     Path bogusDir = scratch.file("/exec/dir/bogus");
-    try {
-      new Artifact(ArtifactRoot.asDerivedRoot(execDir, bogusDir), f1.relativeTo(execDir));
-      fail("Expected IllegalArgumentException constructing artifact with a bad root dir");
-    } catch (IllegalArgumentException expected) {}
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> new Artifact(ArtifactRoot.asDerivedRoot(execDir, bogusDir), f1.relativeTo(execDir)));
   }
 
   @Test
@@ -115,11 +114,7 @@
   @Test
   public void testRootPrefixedExecPath_nullRootDir() throws IOException {
     Path f1 = scratch.file("/exec/dir/file.ext");
-    try {
-      new Artifact(null, f1.relativeTo(execDir));
-      fail("Expected NullPointerException creating artifact with null root");
-    } catch (NullPointerException expected) {
-    }
+    assertThrows(NullPointerException.class, () -> new Artifact(null, f1.relativeTo(execDir)));
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
index 72c782f..f387863 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
@@ -15,6 +15,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.analysis.actions.CustomCommandLine.builder;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 import static org.junit.Assert.fail;
 
 import com.google.common.base.Joiner;
@@ -965,12 +966,7 @@
             .addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo)
             .build();
 
-    try {
-      commandLineTemplate.arguments();
-      fail("No substitution map provided, expected NullPointerException");
-    } catch (NullPointerException e) {
-      // expected
-    }
+    assertThrows(NullPointerException.class, () -> commandLineTemplate.arguments());
   }
 
   private SpecialArtifact createTreeArtifact(String rootRelativePath) {
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java
index f724072..48a99c0 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java
@@ -16,7 +16,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.actions.util.DummyExecutor;
@@ -92,12 +92,9 @@
     Artifact input = new Artifact(dir, inputRoot);
     Artifact output = new Artifact(outputRoot.getRoot().getRelative("some-output"), outputRoot);
     SymlinkAction action = SymlinkAction.toExecutable(NULL_ACTION_OWNER, input, output, "progress");
-    try {
-      action.execute(createContext());
-      fail();
-    } catch (ActionExecutionException e) {
-      assertThat(e).hasMessageThat().contains("'some-dir' is not a file");
-    }
+    ActionExecutionException e =
+        assertThrows(ActionExecutionException.class, () -> action.execute(createContext()));
+    assertThat(e).hasMessageThat().contains("'some-dir' is not a file");
   }
 
   @Test
@@ -108,16 +105,13 @@
     Artifact input = new Artifact(file, inputRoot);
     Artifact output = new Artifact(outputRoot.getRoot().getRelative("some-output"), outputRoot);
     SymlinkAction action = SymlinkAction.toExecutable(NULL_ACTION_OWNER, input, output, "progress");
-    try {
-      action.execute(createContext());
-      fail();
-    } catch (ActionExecutionException e) {
-      String want = "'some-file' is not executable";
+    ActionExecutionException e =
+        assertThrows(ActionExecutionException.class, () -> action.execute(createContext()));
+    String want = "'some-file' is not executable";
       String got = e.getMessage();
-      assertWithMessage(String.format("got %s, want %s", got, want))
-          .that(got.contains(want))
-          .isTrue();
-    }
+    assertWithMessage(String.format("got %s, want %s", got, want))
+        .that(got.contains(want))
+        .isTrue();
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/actions/FailActionTest.java b/src/test/java/com/google/devtools/build/lib/actions/FailActionTest.java
index d640043..4204aef 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/FailActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/FailActionTest.java
@@ -15,7 +15,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.testutil.Scratch;
@@ -54,12 +54,9 @@
 
   @Test
   public void testExecutingItYieldsExceptionWithErrorMessage() {
-    try {
-      failAction.execute(null);
-      fail();
-    } catch (ActionExecutionException e) {
-      assertThat(e).hasMessageThat().isEqualTo(errorMessage);
-    }
+    ActionExecutionException e =
+        assertThrows(ActionExecutionException.class, () -> failAction.execute(null));
+    assertThat(e).hasMessageThat().isEqualTo(errorMessage);
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ResourceManagerTest.java b/src/test/java/com/google/devtools/build/lib/actions/ResourceManagerTest.java
index d294afd1..876a649 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ResourceManagerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ResourceManagerTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.actions;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -312,12 +312,7 @@
           @Override
           public void runTest() {
             Thread.currentThread().interrupt();
-            try {
-              acquire(1999, 0, 0);
-              fail("Didn't throw interrupted exception");
-            } catch (InterruptedException e) {
-              // Expected.
-            }
+            assertThrows(InterruptedException.class, () -> acquire(1999, 0, 0));
           }
         };
     thread1.start();
diff --git a/src/test/java/com/google/devtools/build/skyframe/CycleDeduperTest.java b/src/test/java/com/google/devtools/build/skyframe/CycleDeduperTest.java
index bd14fe7..28f8065 100644
--- a/src/test/java/com/google/devtools/build/skyframe/CycleDeduperTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/CycleDeduperTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.skyframe;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import org.junit.Test;
@@ -42,21 +42,13 @@
 
   @Test
   public void badCycle_Empty() throws Exception {
-    try {
-      cycleDeduper.seen(ImmutableList.<String>of());
-      fail();
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(IllegalStateException.class, () -> cycleDeduper.seen(ImmutableList.<String>of()));
   }
 
   @Test
   public void badCycle_NonUniqueMembers() throws Exception {
-    try {
-      cycleDeduper.seen(ImmutableList.<String>of("a", "b", "a"));
-      fail();
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(
+        IllegalStateException.class,
+        () -> cycleDeduper.seen(ImmutableList.<String>of("a", "b", "a")));
   }
 }
diff --git a/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java b/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
index a24a9bc..aaf5db5 100644
--- a/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
@@ -14,9 +14,9 @@
 package com.google.devtools.build.skyframe;
 
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 import static com.google.devtools.build.skyframe.GraphTester.CONCATENATE;
 import static com.google.devtools.build.skyframe.GraphTester.NODE_TYPE;
-import static org.junit.Assert.fail;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -346,7 +346,7 @@
     eval(/*keepGoing=*/false, parent);
     final Thread mainThread = Thread.currentThread();
     final AtomicReference<SkyKey> badKey = new AtomicReference<>();
-    DirtyTrackingProgressReceiver receiver =
+    final DirtyTrackingProgressReceiver receiver =
         new DirtyTrackingProgressReceiver(
             new EvaluationProgressReceiver.NullEvaluationProgressReceiver() {
               @Override
@@ -373,25 +373,21 @@
                 }
               }
             });
-    try {
-      invalidateWithoutError(receiver, child);
-      fail();
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> invalidateWithoutError(receiver, child));
     assertThat(badKey.get()).isNull();
     assertThat(state.isEmpty()).isFalse();
     final Set<SkyKey> invalidated = Sets.newConcurrentHashSet();
     assertThat(isInvalidated(parent)).isFalse();
     assertThat(graph.get(null, Reason.OTHER, parent).getValue()).isNotNull();
-    receiver = new DirtyTrackingProgressReceiver(
-        new EvaluationProgressReceiver.NullEvaluationProgressReceiver() {
-      @Override
-      public void invalidated(SkyKey skyKey, InvalidationState state) {
-        invalidated.add(skyKey);
-      }
-    });
-    invalidateWithoutError(receiver);
+    final DirtyTrackingProgressReceiver receiver2 =
+        new DirtyTrackingProgressReceiver(
+            new EvaluationProgressReceiver.NullEvaluationProgressReceiver() {
+              @Override
+              public void invalidated(SkyKey skyKey, InvalidationState state) {
+                invalidated.add(skyKey);
+              }
+            });
+    invalidateWithoutError(receiver2);
     assertThat(invalidated).contains(parent);
     assertThat(state.getInvalidationsForTesting()).isEmpty();
 
diff --git a/src/test/java/com/google/devtools/build/skyframe/EmptySkyValueTest.java b/src/test/java/com/google/devtools/build/skyframe/EmptySkyValueTest.java
index 49a763e..7ec95b0 100644
--- a/src/test/java/com/google/devtools/build/skyframe/EmptySkyValueTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/EmptySkyValueTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.skyframe;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -31,12 +31,10 @@
   public void testNotSerializable() throws IOException {
     ObjectOutputStream objOut = new ObjectOutputStream(new ByteArrayOutputStream());
 
-    try {
-      objOut.writeObject(EmptySkyValue.INSTANCE);
-      fail("Expected exception");
-    } catch (UnsupportedOperationException e) {
-      assertThat(e).hasMessageThat().isEqualTo("Java serialization not supported");
-    }
+    UnsupportedOperationException e =
+        assertThrows(
+            UnsupportedOperationException.class, () -> objOut.writeObject(EmptySkyValue.INSTANCE));
+    assertThat(e).hasMessageThat().isEqualTo("Java serialization not supported");
   }
 
 }
diff --git a/src/test/java/com/google/devtools/build/skyframe/ErrorTransienceValueTest.java b/src/test/java/com/google/devtools/build/skyframe/ErrorTransienceValueTest.java
index 7439a25..1ae1185 100644
--- a/src/test/java/com/google/devtools/build/skyframe/ErrorTransienceValueTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/ErrorTransienceValueTest.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.skyframe;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -31,22 +31,17 @@
   public void testNotSerializable() throws IOException {
     ObjectOutputStream objOut = new ObjectOutputStream(new ByteArrayOutputStream());
 
-    try {
-      objOut.writeObject(ErrorTransienceValue.INSTANCE);
-      fail("Expected exception");
-    } catch (UnsupportedOperationException e) {
-      assertThat(e).hasMessageThat().isEqualTo("Java serialization not supported");
-    }
+    UnsupportedOperationException e =
+        assertThrows(
+            UnsupportedOperationException.class,
+            () -> objOut.writeObject(ErrorTransienceValue.INSTANCE));
+    assertThat(e).hasMessageThat().isEqualTo("Java serialization not supported");
   }
 
   @Test
   public void testHashCodeNotSupported() {
-    try {
-      ErrorTransienceValue.INSTANCE.hashCode();
-      fail("Expected exception");
-    } catch (UnsupportedOperationException e) {
-      // Expected.
-    }
+    assertThrows(
+        UnsupportedOperationException.class, () -> ErrorTransienceValue.INSTANCE.hashCode());
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java b/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
index 137d8d3..64fd23b 100644
--- a/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
@@ -15,8 +15,8 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 import static com.google.devtools.build.skyframe.NodeEntrySubjectFactory.assertThatNodeEntry;
-import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -166,12 +166,9 @@
     NodeEntry entry = new InMemoryNodeEntry();
     entry.addReverseDepAndCheckIfDone(null); // Start evaluation.
     entry.markRebuilding();
-    try {
-      setValue(entry, /*value=*/null, /*errorInfo=*/null, /*graphVersion=*/0L);
-      fail();
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(
+        IllegalStateException.class,
+        () -> setValue(entry, /*value=*/ null, /*errorInfo=*/ null, /*graphVersion=*/ 0L));
   }
 
   @Test
@@ -179,12 +176,7 @@
     InMemoryNodeEntry entry = new InMemoryNodeEntry();
     entry.addReverseDepAndCheckIfDone(null); // Start evaluation.
     entry.markRebuilding();
-    try {
-      entry.signalDep(ZERO_VERSION, null);
-      fail();
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(IllegalStateException.class, () -> entry.signalDep(ZERO_VERSION, null));
   }
 
   @Test
@@ -194,12 +186,9 @@
     entry.markRebuilding();
     setValue(entry, new SkyValue() {}, /*errorInfo=*/ null, /*graphVersion=*/ 0L);
     assertThat(entry.isDone()).isTrue();
-    try {
-      setValue(entry, new SkyValue() {}, /*errorInfo=*/ null, /*graphVersion=*/ 1L);
-      fail();
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(
+        IllegalStateException.class,
+        () -> setValue(entry, new SkyValue() {}, /*errorInfo=*/ null, /*graphVersion=*/ 1L));
   }
 
   @Test
@@ -211,12 +200,9 @@
     entry.markDirty(DirtyType.CHANGE);
     entry.addReverseDepAndCheckIfDone(null);
     entry.markRebuilding();
-    try {
-      setValue(entry, new IntegerValue(2), /*errorInfo=*/ null, /*graphVersion=*/ 0L);
-      fail();
-    } catch (ChangedValueAtSameVersionException e) {
-      // Expected.
-    }
+    assertThrows(
+        ChangedValueAtSameVersionException.class,
+        () -> setValue(entry, new IntegerValue(2), /*errorInfo=*/ null, /*graphVersion=*/ 0L));
   }
 
   @Test
@@ -378,12 +364,10 @@
     assertThat(entry.isDirty()).isFalse();
     assertThat(entry.isDone()).isTrue();
     entry.markDirty(DirtyType.CHANGE);
-    try {
-      entry.markDirty(DirtyType.CHANGE);
-      fail("Cannot mark entry changed twice");
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(
+        "Cannot mark entry changed twice",
+        IllegalStateException.class,
+        () -> entry.markDirty(DirtyType.CHANGE));
   }
 
   @Test
@@ -396,12 +380,10 @@
     entry.signalDep(ZERO_VERSION, dep);
     setValue(entry, new SkyValue() {}, /*errorInfo=*/ null, /*graphVersion=*/ 0L);
     entry.markDirty(DirtyType.DIRTY);
-    try {
-      entry.markDirty(DirtyType.DIRTY);
-      fail("Cannot mark entry dirty twice");
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    assertThrows(
+        "Cannot mark entry dirty twice",
+        IllegalStateException.class,
+        () -> entry.markDirty(DirtyType.DIRTY));
   }
 
   @Test
@@ -425,15 +407,14 @@
     SkyKey parent = key("parent");
     assertThat(entry.addReverseDepAndCheckIfDone(parent))
         .isEqualTo(DependencyState.NEEDS_SCHEDULING);
-    try {
-      entry.addReverseDepAndCheckIfDone(parent);
-      entry.markRebuilding();
-      assertThat(setValue(entry, new SkyValue() {}, /*errorInfo=*/null, /*graphVersion=*/0L))
-          .containsExactly(parent);
-      fail("Cannot add same dep twice");
-    } catch (IllegalStateException e) {
-      assertThat(e).hasMessageThat().contains("Duplicate reverse deps");
-    }
+    entry.addReverseDepAndCheckIfDone(parent);
+    entry.markRebuilding();
+    IllegalStateException e =
+        assertThrows(
+            "Cannot add same dep twice",
+            IllegalStateException.class,
+            () -> setValue(entry, new SkyValue() {}, /*errorInfo=*/ null, /*graphVersion=*/ 0L));
+    assertThat(e).hasMessageThat().contains("Duplicate reverse deps");
   }
 
   @Test
@@ -444,14 +425,13 @@
     setValue(entry, new SkyValue() {}, /*errorInfo=*/null, /*graphVersion=*/0L);
     SkyKey parent = key("parent");
     assertThat(entry.addReverseDepAndCheckIfDone(parent)).isEqualTo(DependencyState.DONE);
-    try {
-      entry.addReverseDepAndCheckIfDone(parent);
-      // We only check for duplicates when we request all the reverse deps.
-      entry.getReverseDepsForDoneEntry();
-      fail("Cannot add same dep twice");
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    entry.addReverseDepAndCheckIfDone(parent);
+    assertThrows(
+        "Cannot add same dep twice",
+        IllegalStateException.class,
+        () ->
+            // We only check for duplicates when we request all the reverse deps.
+            entry.getReverseDepsForDoneEntry());
   }
 
   @Test
@@ -462,14 +442,13 @@
         .isEqualTo(DependencyState.NEEDS_SCHEDULING);
     entry.markRebuilding();
     setValue(entry, new SkyValue() {}, /*errorInfo=*/null, /*graphVersion=*/0L);
-    try {
-      entry.addReverseDepAndCheckIfDone(parent);
-      // We only check for duplicates when we request all the reverse deps.
-      entry.getReverseDepsForDoneEntry();
-      fail("Cannot add same dep twice");
-    } catch (IllegalStateException e) {
-      // Expected.
-    }
+    entry.addReverseDepAndCheckIfDone(parent);
+    assertThrows(
+        "Cannot add same dep twice",
+        IllegalStateException.class,
+        () ->
+            // We only check for duplicates when we request all the reverse deps.
+            entry.getReverseDepsForDoneEntry());
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
index 1ddb6ae..6331052 100644
--- a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
@@ -16,6 +16,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 import static com.google.devtools.build.lib.testutil.EventIterableSubjectFactory.assertThatEvents;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 import static com.google.devtools.build.skyframe.ErrorInfoSubjectFactory.assertThatErrorInfo;
 import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult;
 import static com.google.devtools.build.skyframe.GraphTester.CONCATENATE;
@@ -341,12 +342,7 @@
   public void interruptBitCleared() throws Exception {
     SkyKey interruptKey = GraphTester.skyKey("interrupt");
     tester.getOrCreate(interruptKey).setBuilder(INTERRUPT_BUILDER);
-    try {
-      tester.eval(/*keepGoing=*/ true, interruptKey);
-      fail("Expected interrupt");
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> tester.eval(/*keepGoing=*/ true, interruptKey));
     assertThat(Thread.interrupted()).isFalse();
   }
 
@@ -391,17 +387,15 @@
                 null,
                 ImmutableList.<SkyKey>of()));
 
-    try {
-      // When it is interrupted during evaluation (here, caused by the failure of the throwing
-      // SkyFunction during a no-keep-going evaluation),
-      EvaluationResult<StringValue> unexpectedResult =
-          tester.eval(/*keepGoing=*/ false, badInterruptkey, failKey);
-      fail(unexpectedResult.toString());
-    } catch (RuntimeException e) {
-      // Then the Evaluator#evaluate call throws a RuntimeException e where e.getCause() is the
-      // RuntimeException thrown by that SkyFunction.
-      assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("I don't like being woken up!");
-    }
+    // When it is interrupted during evaluation (here, caused by the failure of the throwing
+    // SkyFunction during a no-keep-going evaluation), then the Evaluator#evaluate call throws a
+    // RuntimeException e where e.getCause() is the
+    // RuntimeException thrown by that SkyFunction.
+    RuntimeException e =
+        assertThrows(
+            RuntimeException.class,
+            () -> tester.eval(/*keepGoing=*/ false, badInterruptkey, failKey));
+    assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("I don't like being woken up!");
   }
 
   @Test
@@ -3020,17 +3014,15 @@
             }
           });
       tester.invalidate();
-      TestThread evalThread = new TestThread() {
-        @Override
-        public void runTest() {
-          try {
-            tester.eval(/*keepGoing=*/false, tops.toArray(new SkyKey[0]));
-            fail();
-          } catch (InterruptedException e) {
-            // Expected.
-          }
-        }
-      };
+      TestThread evalThread =
+          new TestThread() {
+            @Override
+            public void runTest() {
+              assertThrows(
+                  InterruptedException.class,
+                  () -> tester.eval(/*keepGoing=*/ false, tops.toArray(new SkyKey[0])));
+            }
+          };
       evalThread.start();
       assertThat(notifyStart.await(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)).isTrue();
       evalThread.interrupt();
@@ -3078,13 +3070,7 @@
     manyDirtyValuesClearChildrenOnFail(/*interrupt=*/true);
   }
 
-  /**
-   * Regression test for case where the user requests that we delete nodes that are already in the
-   * queue to be dirtied. We should handle that gracefully and not complain.
-   */
-  @Test
-  public void deletingDirtyNodes() throws Exception {
-    SkyKey node0 = GraphTester.nonHermeticKey("node0");
+  private SkyKey makeTestKey(SkyKey node0) {
     SkyKey key = null;
     // Create a long chain of nodes. Most of them will not actually be dirtied, but the last one to
     // be dirtied will enqueue its parent for dirtying, so it will be in the queue for the next run.
@@ -3098,6 +3084,17 @@
         tester.set(key, new StringValue("node0"));
       }
     }
+    return key;
+  }
+
+  /**
+   * Regression test for case where the user requests that we delete nodes that are already in the
+   * queue to be dirtied. We should handle that gracefully and not complain.
+   */
+  @Test
+  public void deletingDirtyNodes() throws Exception {
+    SkyKey node0 = GraphTester.nonHermeticKey("node0");
+    SkyKey key = makeTestKey(node0);
     // Seed the graph.
     assertThat(((StringValue) tester.evalAndGet(/*keepGoing=*/ false, key)).getValue())
         .isEqualTo("node0");
@@ -3109,12 +3106,7 @@
     final Thread thread = Thread.currentThread();
     tester.progressReceiver.setNextInvalidationCallback(thread::interrupt);
 
-    try {
-      tester.eval(/*keepGoing=*/false, key);
-      fail();
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> tester.eval(/*keepGoing=*/ false, key));
 
     // Cleanup + paranoid check
     tester.progressReceiver.setNextInvalidationCallback(null);
@@ -3393,12 +3385,7 @@
     // Evaluator will think leaf was interrupted because it threw, so it will be cleaned from graph.
     tester.getOrCreate(value, /*markAsModified=*/true).setBuilder(INTERRUPT_BUILDER);
     tester.invalidate();
-    try {
-      tester.eval(/*keepGoing=*/false, value);
-      fail();
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> tester.eval(/*keepGoing=*/ false, value));
     tester.getOrCreate(value, /*markAsModified=*/false).setBuilder(null);
   }
 
@@ -3490,12 +3477,9 @@
     // Evaluator will think leaf was interrupted because it threw, so it will be cleaned from graph.
     tester.getOrCreate(leafKey, /*markAsModified=*/true).setBuilder(INTERRUPT_BUILDER);
     tester.invalidate();
-    try {
-      tester.eval(/*keepGoing=*/false, tops.toArray(new SkyKey[0]));
-      fail();
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(
+        InterruptedException.class,
+        () -> tester.eval(/*keepGoing=*/ false, tops.toArray(new SkyKey[0])));
   }
 
   @Test
@@ -4428,12 +4412,7 @@
 
     tester.differencer.inject(ImmutableMap.of(key, val));
     Thread.currentThread().interrupt();
-    try {
-      tester.evalAndGet(/*keepGoing=*/ false, key);
-      fail();
-    } catch (InterruptedException expected) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> tester.evalAndGet(/*keepGoing=*/ false, key));
     SkyValue newVal = tester.evalAndGet(/*keepGoing=*/ false, key);
     assertThat(newVal).isEqualTo(val);
   }
@@ -4988,13 +4967,7 @@
     // And so is top,
     tester.getOrCreate(topKey, /*markAsModified=*/ true);
     tester.invalidate();
-    try {
-      // Then evaluation is interrupted,
-      tester.eval(/*keepGoing=*/ false, topKey);
-      fail();
-    } catch (InterruptedException e) {
-      // Expected.
-    }
+    assertThrows(InterruptedException.class, () -> tester.eval(/*keepGoing=*/ false, topKey));
     // But inactive is still present,
     assertThat(tester.driver.getEntryForTesting(inactiveKey)).isNotNull();
     // And still dirty,
diff --git a/src/test/java/com/google/devtools/build/skyframe/ParallelEvaluatorTest.java b/src/test/java/com/google/devtools/build/skyframe/ParallelEvaluatorTest.java
index b92b76c..73444e2 100644
--- a/src/test/java/com/google/devtools/build/skyframe/ParallelEvaluatorTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/ParallelEvaluatorTest.java
@@ -17,6 +17,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 import static com.google.devtools.build.lib.testutil.EventIterableSubjectFactory.assertThatEvents;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
 import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult;
 import static com.google.devtools.build.skyframe.GraphTester.CONCATENATE;
 import static org.junit.Assert.fail;
@@ -220,12 +221,9 @@
                   return null;
                 }
                 assertThat(future.isDone()).isTrue();
-                try {
-                  future.get();
-                  fail();
-                } catch (ExecutionException expected) {
-                  assertThat(expected.getCause()).isInstanceOf(UnsupportedOperationException.class);
-                }
+                ExecutionException expected =
+                    assertThrows(ExecutionException.class, () -> future.get());
+                assertThat(expected.getCause()).isInstanceOf(UnsupportedOperationException.class);
                 return new StringValue("Caught!");
               }
 
@@ -454,17 +452,13 @@
 
     // And we have a dedicated thread that kicks off the evaluation of A and B together (in that
     // order).
-    TestThread evalThread = new TestThread() {
-      @Override
-      public void runTest() throws Exception {
-        try {
-          eval(/*keepGoing=*/true, keyA, keyB);
-          fail();
-        } catch (InterruptedException e) {
-          // Expected.
-        }
-      }
-    };
+    TestThread evalThread =
+        new TestThread() {
+          @Override
+          public void runTest() throws Exception {
+            assertThrows(InterruptedException.class, () -> eval(/*keepGoing=*/ true, keyA, keyB));
+          }
+        };
 
     // Then when we start that thread,
     evalThread.start();
@@ -523,17 +517,14 @@
                 receivedValues.add(skyKey);
               }
             });
-    TestThread evalThread = new TestThread() {
-      @Override
-      public void runTest() throws Exception {
-        try {
-          eval(/*keepGoing=*/true, waitKey, fastKey);
-          fail();
-        } catch (InterruptedException e) {
-          // Expected.
-        }
-      }
-    };
+    TestThread evalThread =
+        new TestThread() {
+          @Override
+          public void runTest() throws Exception {
+            assertThrows(
+                InterruptedException.class, () -> eval(/*keepGoing=*/ true, waitKey, fastKey));
+          }
+        };
     evalThread.start();
     assertThat(allValuesReady.await(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)).isTrue();
     evalThread.interrupt();
@@ -660,15 +651,12 @@
             new InMemoryGraphImpl(), ImmutableMap.of(GraphTester.NODE_TYPE, builder), false);
 
     SkyKey valueToEval = GraphTester.toSkyKey("a");
-    try {
-      evaluator.eval(ImmutableList.of(valueToEval));
-      fail("Expected RuntimeException");
-    } catch (RuntimeException re) {
-      assertThat(re)
-          .hasMessageThat()
-          .contains("Unrecoverable error while evaluating node '" + valueToEval.toString() + "'");
-      assertThat(re).hasCauseThat().isInstanceOf(CustomRuntimeException.class);
-    }
+    RuntimeException re =
+        assertThrows(RuntimeException.class, () -> evaluator.eval(ImmutableList.of(valueToEval)));
+    assertThat(re)
+        .hasMessageThat()
+        .contains("Unrecoverable error while evaluating node '" + valueToEval.toString() + "'");
+    assertThat(re).hasCauseThat().isInstanceOf(CustomRuntimeException.class);
   }
 
   @Test
@@ -1915,17 +1903,16 @@
             PARENT_TYPE, new ParentFunction());
     ParallelEvaluator evaluator = makeEvaluator(new InMemoryGraphImpl(), skyFunctions, false);
 
-    try {
-      evaluator.eval(ImmutableList.of(ParentKey.create("octodad")));
-      fail();
-    } catch (RuntimeException e) {
-      assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("I WANT A PONY!!!");
-      assertThat(e)
-          .hasMessageThat()
-          .isEqualTo(
-              "Unrecoverable error while evaluating node 'child:billy the kid' "
-                  + "(requested by nodes 'parent:octodad')");
-    }
+    RuntimeException e =
+        assertThrows(
+            RuntimeException.class,
+            () -> evaluator.eval(ImmutableList.of(ParentKey.create("octodad"))));
+    assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("I WANT A PONY!!!");
+    assertThat(e)
+        .hasMessageThat()
+        .isEqualTo(
+            "Unrecoverable error while evaluating node 'child:billy the kid' "
+                + "(requested by nodes 'parent:octodad')");
   }
 
   private static class SomeOtherErrorException extends Exception {
diff --git a/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java b/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java
index c846771..7d3ffd9 100644
--- a/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java
@@ -15,7 +15,6 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
-import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Interner;
@@ -107,11 +106,7 @@
     // Should only fail when we call getReverseDeps().
     ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
     ReverseDepsUtility.removeReverseDep(example, key);
-    try {
-      ReverseDepsUtility.getReverseDeps(example);
-      fail();
-    } catch (IllegalStateException expected) {
-    }
+    assertThrows(IllegalStateException.class, () -> ReverseDepsUtility.getReverseDeps(example));
   }
 
   @Test
@@ -124,11 +119,8 @@
     ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
     ReverseDepsUtility.removeReverseDep(example, key);
     ReverseDepsUtility.checkReverseDep(example, fixedKey);
-    try {
-      ReverseDepsUtility.checkReverseDep(example, fixedKey);
-      fail();
-    } catch (IllegalStateException expected) {
-    }
+    assertThrows(
+        IllegalStateException.class, () -> ReverseDepsUtility.checkReverseDep(example, fixedKey));
   }
 
   @Test