Automatic cleanup change.
PiperOrigin-RevId: 246021743
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandlerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandlerTest.java
index 6620ee0..bdf3b18 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandlerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandlerTest.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.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 com.google.common.collect.ImmutableMap;
@@ -104,12 +104,9 @@
/* tsgm= */ null,
ArtifactPathResolver.IDENTITY,
new MinimalOutputStore());
- try {
- handler.getMetadata(artifact);
- fail();
- } catch (IllegalStateException expected) {
- assertThat(expected).hasMessageThat().contains("null for ");
- }
+ IllegalStateException expected =
+ assertThrows(IllegalStateException.class, () -> handler.getMetadata(artifact));
+ assertThat(expected).hasMessageThat().contains("null for ");
}
@Test
@@ -170,11 +167,7 @@
/* tsgm= */ null,
ArtifactPathResolver.IDENTITY,
new MinimalOutputStore());
- try {
- handler.getMetadata(artifact);
- fail();
- } catch (FileNotFoundException expected) {
- }
+ assertThrows(FileNotFoundException.class, () -> handler.getMetadata(artifact));
}
@Test
@@ -189,11 +182,7 @@
/* tsgm= */ null,
ArtifactPathResolver.IDENTITY,
new MinimalOutputStore());
- try {
- handler.getMetadata(artifact);
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> handler.getMetadata(artifact));
}
@Test
@@ -249,11 +238,7 @@
/* tsgm= */ null,
ArtifactPathResolver.IDENTITY,
new MinimalOutputStore());
- try {
- handler.getMetadata(artifact);
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> handler.getMetadata(artifact));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java
index 4e8bbea..2596d8f 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.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.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -144,12 +144,7 @@
.setOutputPathMapper(mapper)
.build(ActionsTestUtil.NULL_ACTION_OWNER);
- try {
- evaluate(spawnActionTemplate);
- fail("Expected ActionConflictException");
- } catch (ActionConflictException e) {
- // Expected ActionConflictException
- }
+ assertThrows(ActionConflictException.class, () -> evaluate(spawnActionTemplate));
}
@Test
@@ -185,12 +180,7 @@
.setOutputPathMapper(mapper)
.build(ActionsTestUtil.NULL_ACTION_OWNER);
- try {
- evaluate(spawnActionTemplate);
- fail("Expected ArtifactPrefixConflictException");
- } catch (ArtifactPrefixConflictException e) {
- // Expected ArtifactPrefixConflictException
- }
+ assertThrows(ArtifactPrefixConflictException.class, () -> evaluate(spawnActionTemplate));
}
private static final ActionLookupValue.ActionLookupKey CTKEY = new InjectedActionLookupKey("key");
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index 52de5fe..7b25f59 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -15,7 +15,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.FileArtifactValue.create;
-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;
@@ -133,12 +133,8 @@
@Test
public void testMissingMandatoryArtifact() throws Throwable {
Artifact input = createSourceArtifact("input1");
- try {
- evaluateArtifactValue(input, /*mandatory=*/ true);
- fail();
- } catch (MissingInputFileException ex) {
- // Expected.
- }
+ assertThrows(
+ MissingInputFileException.class, () -> evaluateArtifactValue(input, /*mandatory=*/ true));
}
@Test
@@ -186,12 +182,11 @@
return super.statIfFound(path, followSymlinks);
}
});
- try {
- evaluateArtifactValue(createSourceArtifact("bad"));
- fail();
- } catch (MissingInputFileException e) {
- assertThat(e).hasMessageThat().contains(exception.getMessage());
- }
+ MissingInputFileException e =
+ assertThrows(
+ MissingInputFileException.class,
+ () -> evaluateArtifactValue(createSourceArtifact("bad")));
+ assertThat(e).hasMessageThat().contains(exception.getMessage());
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
index b8ab9ba..25e317a 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
@@ -15,7 +15,7 @@
package com.google.devtools.build.lib.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.base.Supplier;
import com.google.common.base.VerifyException;
@@ -287,22 +287,22 @@
private void internalTestPutOnlyEntry(Multimap<String, String> map) throws Exception {
ConfigurationResolver.putOnlyEntry(map, "foo", "bar");
ConfigurationResolver.putOnlyEntry(map, "baz", "bar");
- try {
- ConfigurationResolver.putOnlyEntry(map, "foo", "baz");
- fail("Expected an exception when trying to add a new value to an existing key");
- } catch (VerifyException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("couldn't insert baz: map already has values for key foo: [bar]");
- }
- try {
- ConfigurationResolver.putOnlyEntry(map, "foo", "bar");
- fail("Expected an exception when trying to add a pre-existing <key, value> pair");
- } catch (VerifyException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("couldn't insert bar: map already has values for key foo: [bar]");
- }
+ VerifyException e =
+ assertThrows(
+ "Expected an exception when trying to add a new value to an existing key",
+ VerifyException.class,
+ () -> ConfigurationResolver.putOnlyEntry(map, "foo", "baz"));
+ assertThat(e)
+ .hasMessageThat()
+ .isEqualTo("couldn't insert baz: map already has values for key foo: [bar]");
+ e =
+ assertThrows(
+ "Expected an exception when trying to add a pre-existing <key, value> pair",
+ VerifyException.class,
+ () -> ConfigurationResolver.putOnlyEntry(map, "foo", "bar"));
+ assertThat(e)
+ .hasMessageThat()
+ .isEqualTo("couldn't insert bar: map already has values for key foo: [bar]");
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
index d689928..e0efac9 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
@@ -15,7 +15,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.FileArtifactValue.createShareable;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import com.google.common.io.BaseEncoding;
import com.google.common.testing.EqualsTester;
@@ -144,12 +144,10 @@
FileArtifactValue value = createShareable(path);
assertThat(value.getDigest()).isEqualTo(path.getDigest());
assertThat(value.getSize()).isEqualTo(3L);
- try {
- value.getModifiedTime();
- fail("mtime for non-empty file should not be stored.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
+ assertThrows(
+ "mtime for non-empty file should not be stored.",
+ UnsupportedOperationException.class,
+ () -> value.getModifiedTime());
}
@Test
@@ -168,12 +166,10 @@
FileArtifactValue value = createShareable(path);
assertThat(value.getDigest()).isEqualTo(path.getDigest());
assertThat(value.getSize()).isEqualTo(0L);
- try {
- value.getModifiedTime();
- fail("mtime for non-empty file should not be stored.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
+ assertThrows(
+ "mtime for non-empty file should not be stored.",
+ UnsupportedOperationException.class,
+ () -> value.getModifiedTime());
}
@Test
@@ -194,12 +190,8 @@
Path path = fs.getPath("/some/path");
path.getParentDirectory().createDirectoryAndParents();
FileSystemUtils.writeContentAsLatin1(path, "content");
- try {
- createShareable(path);
- fail();
- } catch (IOException e) {
- assertThat(e).isSameAs(exception);
- }
+ IOException e = assertThrows(IOException.class, () -> createShareable(path));
+ assertThat(e).isSameAs(exception);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index ecef27c..fc4ed3c 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -825,38 +825,20 @@
assertThat(valueForPath(file).getSize()).isEqualTo(fileSize);
Path dir = directory("directory");
file(dir.getChild("child").getPathString());
- try {
- valueForPath(dir).getSize();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
+ assertThrows(IllegalStateException.class, () -> valueForPath(dir).getSize());
Path nonexistent = fs.getPath("/root/noexist");
- try {
- valueForPath(nonexistent).getSize();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
- Path symlink = symlink("link", "/root/file");
+ assertThrows(IllegalStateException.class, () -> valueForPath(nonexistent).getSize());
+ Path fileSymlink = symlink("link", "/root/file");
// Symlink stores size of target, not link.
- assertThat(valueForPath(symlink).getSize()).isEqualTo(fileSize);
- assertThat(symlink.delete()).isTrue();
- symlink = symlink("link", "/root/directory");
- try {
- valueForPath(symlink).getSize();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
- assertThat(symlink.delete()).isTrue();
- symlink = symlink("link", "/root/noexist");
- try {
- valueForPath(symlink).getSize();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
+ assertThat(valueForPath(fileSymlink).getSize()).isEqualTo(fileSize);
+ assertThat(fileSymlink.delete()).isTrue();
+
+ Path rootDirSymlink = symlink("link", "/root/directory");
+ assertThrows(IllegalStateException.class, () -> valueForPath(rootDirSymlink).getSize());
+ assertThat(rootDirSymlink.delete()).isTrue();
+
+ Path noExistSymlink = symlink("link", "/root/noexist");
+ assertThrows(IllegalStateException.class, () -> valueForPath(noExistSymlink).getSize());
}
@Test
@@ -892,20 +874,13 @@
assertThat(digestCalls.get()).isEqualTo(0);
fastDigest = true;
Path dir = directory("directory");
- try {
- assertThat(valueForPath(dir).getDigest()).isNull();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
+ assertThrows(
+ IllegalStateException.class, () -> assertThat(valueForPath(dir).getDigest()).isNull());
assertThat(digestCalls.get()).isEqualTo(0); // No digest calls made for directory.
Path nonexistent = fs.getPath("/root/noexist");
- try {
- assertThat(valueForPath(nonexistent).getDigest()).isNull();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
+ assertThrows(
+ IllegalStateException.class,
+ () -> assertThat(valueForPath(nonexistent).getDigest()).isNull());
assertThat(digestCalls.get()).isEqualTo(0); // No digest calls made for nonexistent file.
Path symlink = symlink("link", "/root/file");
value = valueForPath(symlink);
@@ -915,14 +890,10 @@
assertThat(digestCalls.get()).isEqualTo(1);
digestCalls.set(0);
assertThat(symlink.delete()).isTrue();
- symlink = symlink("link", "/root/directory");
// Symlink stores digest of target, not link, for directories too.
- try {
- assertThat(valueForPath(symlink).getDigest()).isNull();
- fail();
- } catch (IllegalStateException e) {
- // Expected.
- }
+ assertThrows(
+ IllegalStateException.class,
+ () -> assertThat(valueForPath(symlink("link", "/root/directory")).getDigest()).isNull());
assertThat(digestCalls.get()).isEqualTo(0);
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
index 5aa5a69..931719a 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.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.ActionInputHelper.treeFileArtifact;
-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;
@@ -951,12 +951,9 @@
assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker));
fs.statThrowsRuntimeException = true;
- try {
- getDirtyFilesystemKeys(evaluator, checker);
- fail();
- } catch (RuntimeException e) {
- assertThat(e).hasMessageThat().isEqualTo("bork");
- }
+ RuntimeException e =
+ assertThrows(RuntimeException.class, () -> getDirtyFilesystemKeys(evaluator, checker));
+ assertThat(e).hasMessageThat().isEqualTo("bork");
}
private static void assertEmptyDiff(Diff diff) {
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
index fdfb58e..3d85f63 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.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.base.Functions;
import com.google.common.base.Optional;
@@ -520,12 +520,12 @@
}
private void assertIllegalPattern(String pattern) {
- try {
- GlobValue.key(PKG_ID, Root.fromPath(root), pattern, false, PathFragment.EMPTY_FRAGMENT);
- fail("invalid pattern not detected: " + pattern);
- } catch (InvalidGlobPatternException e) {
- // Expected.
- }
+ assertThrows(
+ "invalid pattern not detected: " + pattern,
+ InvalidGlobPatternException.class,
+ () ->
+ GlobValue.key(
+ PKG_ID, Root.fromPath(root), pattern, false, PathFragment.EMPTY_FRAGMENT));
}
/**
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
index f20cc1b..153b0ee 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.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.EvaluationResultSubjectFactory.assertThatEvaluationResult;
import static org.junit.Assert.fail;
@@ -625,11 +626,7 @@
PackageValue value = validPackage(skyKey);
assertThat(value.getPackage().containsErrors()).isFalse();
assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
- try {
- value.getPackage().getTarget("dangling.txt");
- fail();
- } catch (NoSuchTargetException expected) {
- }
+ assertThrows(NoSuchTargetException.class, () -> value.getPackage().getTarget("dangling.txt"));
scratch.overwriteFile(
"foo/BUILD", "exports_files(glob(['*.txt']))", "#some-irrelevant-comment");
@@ -640,17 +637,13 @@
ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(),
Root.fromPath(rootDirectory));
- value = validPackage(skyKey);
- assertThat(value.getPackage().containsErrors()).isFalse();
- assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
- try {
- value.getPackage().getTarget("dangling.txt");
- fail();
- } catch (NoSuchTargetException expected) {
- // One consequence of the bug was that dangling symlinks were matched by globs evaluated by
- // Skyframe globbing, meaning there would incorrectly be corresponding targets in packages
- // that had skyframe cache hits during skyframe hybrid globbing.
- }
+ PackageValue value2 = validPackage(skyKey);
+ assertThat(value2.getPackage().containsErrors()).isFalse();
+ assertThat(value2.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
+ assertThrows(NoSuchTargetException.class, () -> value2.getPackage().getTarget("dangling.txt"));
+ // One consequence of the bug was that dangling symlinks were matched by globs evaluated by
+ // Skyframe globbing, meaning there would incorrectly be corresponding targets in packages
+ // that had skyframe cache hits during skyframe hybrid globbing.
scratch.file("foo/nope");
getSkyframeExecutor()
@@ -684,11 +677,7 @@
PackageValue value = validPackage(skyKey);
assertThat(value.getPackage().containsErrors()).isFalse();
assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched");
- try {
- value.getPackage().getTarget("-matched");
- fail();
- } catch (NoSuchTargetException expected) {
- }
+ assertThrows(NoSuchTargetException.class, () -> value.getPackage().getTarget("-matched"));
scratch.overwriteFile(
"foo/BUILD",
@@ -700,14 +689,10 @@
ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(),
Root.fromPath(rootDirectory));
- value = validPackage(skyKey);
- assertThat(value.getPackage().containsErrors()).isFalse();
- assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched");
- try {
- value.getPackage().getTarget("-matched");
- fail();
- } catch (NoSuchTargetException expected) {
- }
+ PackageValue value2 = validPackage(skyKey);
+ assertThat(value2.getPackage().containsErrors()).isFalse();
+ assertThat(value2.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched");
+ assertThrows(NoSuchTargetException.class, () -> value2.getPackage().getTarget("-matched"));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ParallelBuilderTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ParallelBuilderTest.java
index 60ce28c..52a8eef 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ParallelBuilderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ParallelBuilderTest.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.MoreAsserts.assertThrows;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
@@ -222,16 +223,12 @@
reporter.removeHandler(failFastHandler);
// test that building 'foo' fails
- try {
- buildArtifacts(foo);
- fail("building 'foo' was supposed to fail!");
- } catch (BuildFailedException e) {
- if (!e.getMessage().contains("building 'foo' is supposed to fail")) {
+ BuildFailedException e = assertThrows(BuildFailedException.class, () -> buildArtifacts(foo));
+ if (!e.getMessage().contains("building 'foo' is supposed to fail")) {
throw e;
}
- // Make sure the reporter reported the error message.
- assertContainsEvent("building 'foo' is supposed to fail");
- }
+ // Make sure the reporter reported the error message.
+ assertContainsEvent("building 'foo' is supposed to fail");
// test that a subsequent build of 'bar' succeeds
buildArtifacts(bar);
}
@@ -293,12 +290,8 @@
Artifact foo = createDerivedArtifact(fs, "foo");
registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
reporter.removeHandler(failFastHandler);
- try {
- buildArtifacts(foo);
- fail("Expected to fail");
- } catch (BuildFailedException e) {
- assertContainsEvent("not all outputs were created or valid");
- }
+ assertThrows(BuildFailedException.class, () -> buildArtifacts(foo));
+ assertContainsEvent("not all outputs were created or valid");
}
@Test
@@ -546,15 +539,12 @@
// Don't fail fast when we encounter the error
reporter.removeHandler(failFastHandler);
- try {
- buildArtifacts(foo, bar);
- fail();
- } catch (BuildFailedException e) {
- assertThat(e)
- .hasMessageThat()
- .contains("TestAction failed due to exception: foo action failed");
- assertContainsEvent("TestAction failed due to exception: foo action failed");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifacts(foo, bar));
+ assertThat(e)
+ .hasMessageThat()
+ .contains("TestAction failed due to exception: foo action failed");
+ assertContainsEvent("TestAction failed due to exception: foo action failed");
assertWithMessage("bar action not finished, yet buildArtifacts has completed.")
.that(finished[0])
@@ -569,28 +559,28 @@
Artifact foo = createDerivedArtifact("foo");
Artifact bar = createDerivedArtifact("bar");
Artifact baz = createDerivedArtifact("baz");
- try {
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(foo)));
- buildArtifacts(foo);
- fail("Builder failed to detect cyclic action graph");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
- }
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(foo)));
+ BuildFailedException e =
+ assertThrows(
+ "Builder failed to detect cyclic action graph",
+ BuildFailedException.class,
+ () -> buildArtifacts(foo));
+ assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
}
@Test
public void testSelfCyclicActionGraph() throws Exception {
// foo -> [action] -> foo
Artifact foo = createDerivedArtifact("foo");
- try {
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(foo)));
- buildArtifacts(foo);
- fail("Builder failed to detect cyclic action graph");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
- }
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(foo)));
+ BuildFailedException e =
+ assertThrows(
+ "Builder failed to detect cyclic action graph",
+ BuildFailedException.class,
+ () -> buildArtifacts(foo));
+ assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
}
@Test
@@ -603,16 +593,16 @@
Artifact foo2 = createDerivedArtifact("foo2");
Artifact bar = createDerivedArtifact("bar");
Artifact baz = createDerivedArtifact("baz");
- try {
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo1)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo2)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
- buildArtifacts(foo1, foo2);
- fail("Builder failed to detect cyclic action graph");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
- }
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo1)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo2)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
+ BuildFailedException e =
+ assertThrows(
+ "Builder failed to detect cyclic action graph",
+ BuildFailedException.class,
+ () -> buildArtifacts(foo1, foo2));
+ assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
}
@@ -625,16 +615,16 @@
Artifact bar = createDerivedArtifact("bar");
Artifact baz = createDerivedArtifact("baz");
Artifact bat = createDerivedArtifact("bat");
- try {
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
- registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bat, foo), asSet(baz)));
- registerAction(new TestAction(TestAction.NO_EFFECT, ImmutableSet.<Artifact>of(), asSet(bat)));
- buildArtifacts(foo);
- fail("Builder failed to detect cyclic action graph");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
- }
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bat, foo), asSet(baz)));
+ registerAction(new TestAction(TestAction.NO_EFFECT, ImmutableSet.<Artifact>of(), asSet(bat)));
+ BuildFailedException e =
+ assertThrows(
+ "Builder failed to detect cyclic action graph",
+ BuildFailedException.class,
+ () -> buildArtifacts(foo));
+ assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG);
}
@Test
@@ -710,12 +700,9 @@
// Don't fail fast when we encounter the error
reporter.removeHandler(failFastHandler);
- try {
- buildArtifacts(createBuilder(3, keepGoing), artifacts);
- fail();
- } catch (BuildFailedException e) {
- assertContainsEvent("task failed");
- }
+ assertThrows(
+ BuildFailedException.class, () -> buildArtifacts(createBuilder(3, keepGoing), artifacts));
+ assertContainsEvent("task failed");
if (completedTasks.get() >= numJobs) {
fail("Expected early termination due to failed task, but all tasks ran to completion.");
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
index 3f5c4cf..42399c0 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
@@ -21,8 +21,8 @@
import static com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory.regularFile;
import static com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory.symlinkToDirectory;
import static com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory.symlinkToFile;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -353,12 +353,10 @@
// No exception thrown, let's safely compare results.
assertEquals(expected.getTargetInSymlinkTree(true), actual.getTargetInSymlinkTree(true));
} catch (DanglingSymlinkException e) {
- try {
- actual.getTargetInSymlinkTree(true);
- fail("Expected exception not thrown while requesting resolved symlink.");
- } catch (DanglingSymlinkException e1) {
- // exception thrown by both expected and actual we're all good.
- }
+ assertThrows(
+ "Expected exception not thrown while requesting resolved symlink.",
+ DanglingSymlinkException.class,
+ () -> actual.getTargetInSymlinkTree(true));
}
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java
index 158d6e2..7df9c43 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java
@@ -13,7 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
@@ -40,12 +40,9 @@
private void invalidHelper(
PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) {
- try {
- buildRecursivePkgKey(
- RepositoryName.MAIN, rootRelativePath, excludedPaths);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> buildRecursivePkgKey(RepositoryName.MAIN, rootRelativePath, excludedPaths));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
index 1903208..2f748a6 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe;
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;
@@ -85,7 +86,7 @@
assertThat(sym1.delete()).isTrue();
FileSystemUtils.ensureSymbolicLink(sym1, path);
assertThat(symlink.delete()).isTrue();
- symlink = scratch.file("bar/BUILD", "sh_library(name = 'bar')");
+ scratch.file("bar/BUILD", "sh_library(name = 'bar')");
syncPackages();
assertLabelsVisited(
ImmutableSet.of("//bar:bar"), ImmutableSet.of("//bar:bar"), !EXPECT_ERROR, !KEEP_GOING);
@@ -293,12 +294,10 @@
scratch.file("x/BUILD");
Thread.currentThread().interrupt();
- try {
- assertLabelsVisitedWithErrors(ImmutableSet.of("//x:x"), ImmutableSet.of("//x:BUILD"));
- fail();
- } catch (InterruptedException e) {
- // Expected
- }
+ assertThrows(
+ InterruptedException.class,
+ () ->
+ assertLabelsVisitedWithErrors(ImmutableSet.of("//x:x"), ImmutableSet.of("//x:BUILD")));
}
// Regression test for "crash when // encountered in package name".
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
index 7d412d8..54ae227 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.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.EvaluationResultSubjectFactory.assertThatEvaluationResult;
import static org.junit.Assert.fail;
@@ -218,18 +219,19 @@
public void testSkylarkImportFilenameWithControlChars() throws Exception {
scratch.file("pkg/BUILD", "");
scratch.file("pkg/ext.bzl", "load('//pkg:oops\u0000.bzl', 'a')");
- try {
- SkyKey skylarkImportLookupKey = key("//pkg:ext.bzl");
- SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter);
- fail("Expected exception");
- } catch (AssertionError e) {
- String errorMessage = e.getMessage();
- assertThat(errorMessage)
- .contains(
- "invalid target name 'oops<?>.bzl': "
- + "target names may not contain non-printable characters: '\\x00'");
- }
+ AssertionError e =
+ assertThrows(
+ AssertionError.class,
+ () -> {
+ SkyKey skylarkImportLookupKey = key("//pkg:ext.bzl");
+ SkyframeExecutorTestUtils.evaluate(
+ getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ });
+ String errorMessage = e.getMessage();
+ assertThat(errorMessage)
+ .contains(
+ "invalid target name 'oops<?>.bzl': "
+ + "target names may not contain non-printable characters: '\\x00'");
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderMediumTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderMediumTest.java
index beb661f..80aba30 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderMediumTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderMediumTest.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.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 com.google.common.collect.Iterables;
@@ -415,14 +415,10 @@
// Now first cache creation attempt should cause IOException while renaming corrupted files.
// Second attempt will initialize empty cache, causing rebuild.
- try {
- createCache();
- fail("Expected IOException");
- } catch (IOException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("Failed action cache referential integrity check: empty index");
- }
+ IOException e = assertThrows(IOException.class, () -> createCache());
+ assertThat(e)
+ .hasMessageThat()
+ .isEqualTo("Failed action cache referential integrity check: empty index");
buildArtifacts(persistentBuilder(createCache()), hello);
assertThat(button.pressed).isTrue(); // rebuilt due to the missing filename index
@@ -480,12 +476,8 @@
// Now first cache creation attempt should cause IOException while renaming corrupted files.
// Second attempt will initialize empty cache, causing rebuild.
- try {
- createCache();
- fail("Expected IOException");
- } catch (IOException e) {
- assertThat(e).hasMessageThat().contains("Failed action cache referential integrity check");
- }
+ IOException e = assertThrows(IOException.class, () -> createCache());
+ assertThat(e).hasMessageThat().contains("Failed action cache referential integrity check");
// Validate cache with incorrect (out-of-date) filename index.
buildArtifacts(persistentBuilder(createCache()), hello);
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTest.java
index 84cf0a2..531f25f 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTest.java
@@ -15,7 +15,7 @@
package com.google.devtools.build.lib.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.Sets;
import com.google.devtools.build.lib.actions.Artifact;
@@ -82,12 +82,12 @@
public void testBuildingNonexistentSourcefileFails() throws Exception {
reporter.removeHandler(failFastHandler);
Artifact hello = createSourceArtifact("hello");
- try {
- buildArtifacts(cachingBuilder(), hello);
- fail("Expected input file to be missing");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().isEqualTo("missing input file '" + hello.getPath() + "'");
- }
+ BuildFailedException e =
+ assertThrows(
+ "Expected input file to be missing",
+ BuildFailedException.class,
+ () -> buildArtifacts(cachingBuilder(), hello));
+ assertThat(e).hasMessageThat().isEqualTo("missing input file '" + hello.getPath() + "'");
}
@Test
@@ -324,11 +324,8 @@
registerAction(new TestAction(TestAction.NO_EFFECT, Collections.singleton(in),
Collections.singleton(out)));
- try {
- buildArtifacts(amnesiacBuilder(), out); // fails with ActionExecutionException
- fail();
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().contains("1 input file(s) do not exist");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifacts(amnesiacBuilder(), out));
+ assertThat(e).hasMessageThat().contains("1 input file(s) do not exist");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
index 7d7e221..b990867 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
@@ -15,7 +15,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
@@ -420,17 +420,13 @@
};
registerAction(failureOne);
- try {
- buildArtifact(outOne);
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- //not all outputs were created
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
- assertThat(errors).hasSize(2);
- assertThat(errors.get(0).getMessage()).contains("not present on disk");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThrows(BuildFailedException.class, () -> buildArtifact(outOne));
+ // not all outputs were created
+ List<Event> errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThat(errors).hasSize(2);
+ assertThat(errors.get(0).getMessage()).contains("not present on disk");
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
TreeArtifactTestAction failureTwo = new TreeArtifactTestAction(
Runnables.doNothing(), outTwoFileOne, outTwoFileTwo) {
@@ -451,16 +447,12 @@
registerAction(failureTwo);
storingEventHandler.clear();
- try {
- buildArtifact(outTwo);
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
- assertThat(errors).hasSize(2);
- assertThat(errors.get(0).getMessage()).contains("not present on disk");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThrows(BuildFailedException.class, () -> buildArtifact(outTwo));
+ errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThat(errors).hasSize(2);
+ assertThat(errors.get(0).getMessage()).contains("not present on disk");
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
private static void checkDirectoryPermissions(Path path) throws IOException {
@@ -562,17 +554,13 @@
registerAction(action);
- try {
- buildArtifact(action.getSoleOutput());
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThrows(BuildFailedException.class, () -> buildArtifact(action.getSoleOutput()));
+ List<Event> errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains(
"Failed to resolve relative path links/link");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
@Test
@@ -602,16 +590,12 @@
registerAction(action);
- try {
- buildArtifact(action.getSoleOutput());
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThrows(BuildFailedException.class, () -> buildArtifact(action.getSoleOutput()));
+ List<Event> errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("Failed to resolve relative path links/link");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
@Test
@@ -668,18 +652,14 @@
registerAction(action);
- try {
- buildArtifact(action.getSoleOutput());
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThrows(BuildFailedException.class, () -> buildArtifact(action.getSoleOutput()));
+ List<Event> errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains(
"A TreeArtifact may not contain relative symlinks whose target paths traverse "
+ "outside of the TreeArtifact");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
@Test
@@ -712,18 +692,14 @@
registerAction(action);
- try {
- buildArtifact(action.getSoleOutput());
- fail(); // Should have thrown
- } catch (BuildFailedException e) {
- List<Event> errors = ImmutableList.copyOf(
- Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
+ assertThrows(BuildFailedException.class, () -> buildArtifact(action.getSoleOutput()));
+ List<Event> errors =
+ ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains(
"A TreeArtifact may not contain relative symlinks whose target paths traverse "
+ "outside of the TreeArtifact");
- assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
- }
+ assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
// This is more a smoke test than anything, because it turns out that:
@@ -837,12 +813,9 @@
new DummyActionTemplateExpansionFunction(
actionKeyContext, ImmutableList.of(generateOutputAction, noGenerateOutputAction));
- try {
- buildArtifact(artifact2);
- fail("Expected BuildFailedException");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().contains("not all outputs were created or valid");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifact(artifact2));
+ assertThat(e).hasMessageThat().contains("not all outputs were created or valid");
}
@Test
@@ -881,12 +854,9 @@
new DummyActionTemplateExpansionFunction(
actionKeyContext, ImmutableList.of(generateOutputAction, throwingAction));
- try {
- buildArtifact(artifact2);
- fail("Expected BuildFailedException");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().contains("Throwing dummy action");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifact(artifact2));
+ assertThat(e).hasMessageThat().contains("Throwing dummy action");
}
@Test
@@ -924,12 +894,9 @@
new DummyActionTemplateExpansionFunction(
actionKeyContext, ImmutableList.of(throwingAction, anotherThrowingAction));
- try {
- buildArtifact(artifact2);
- fail("Expected BuildFailedException");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().contains("Throwing dummy action");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifact(artifact2));
+ assertThat(e).hasMessageThat().contains("Throwing dummy action");
}
@Test
@@ -948,12 +915,9 @@
artifact1, artifact2);
registerAction(actionTemplate);
- try {
- buildArtifact(artifact2);
- fail("Expected BuildFailedException");
- } catch (BuildFailedException e) {
- assertThat(e).hasMessageThat().contains("Throwing dummy action");
- }
+ BuildFailedException e =
+ assertThrows(BuildFailedException.class, () -> buildArtifact(artifact2));
+ assertThat(e).hasMessageThat().contains("Throwing dummy action");
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java
index 76a12ca..a08c30e 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java
@@ -15,7 +15,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.ActionInputHelper.asTreeFileArtifacts;
-import static org.junit.Assert.fail;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
@@ -213,14 +213,12 @@
return super.statIfFound(path, followSymlinks);
}
});
- try {
- Artifact artifact = createTreeArtifact("outOne");
- TreeArtifactValue value = evaluateTreeArtifact(artifact,
- ImmutableList.of(PathFragment.create("one")));
- fail("MissingInputFileException expected, got " + value);
- } catch (Exception e) {
- assertThat(Throwables.getRootCause(e)).hasMessageThat().contains(exception.getMessage());
- }
+ Artifact artifact = createTreeArtifact("outOne");
+ Exception e =
+ assertThrows(
+ Exception.class,
+ () -> evaluateTreeArtifact(artifact, ImmutableList.of(PathFragment.create("one"))));
+ assertThat(Throwables.getRootCause(e)).hasMessageThat().contains(exception.getMessage());
}
private void file(Path path, String contents) throws Exception {