Skip to content

Commit

Permalink
Statically import MoreAsserts.assertThrows everywhere.
Browse files Browse the repository at this point in the history
This will someday help us migrate to Junit's version.

PiperOrigin-RevId: 246368991
  • Loading branch information
katre authored and copybara-github committed May 2, 2019
1 parent 3488aaa commit b0c7ee5
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -212,10 +211,10 @@ public void testAbsoluteArtifact() throws Exception {
.getSourceArtifact(PathFragment.create("/foo"), absoluteRoot)
.getExecPath())
.isEqualTo(PathFragment.create("/foo"));
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> artifactFactory.getSourceArtifact(PathFragment.create("/foo"), clientRoot));
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> artifactFactory.getSourceArtifact(PathFragment.create("foo"), absoluteRoot));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.google.devtools.build.lib.skyframe.serialization.AutoRegistry;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecs;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -297,7 +296,7 @@ public void testToDetailString() throws Exception {
@Test
public void testWeirdArtifact() throws Exception {
Path execRoot = scratch.getFileSystem().getPath("/");
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() ->
new Artifact(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.SingleStringArgFormatter.format;
import static com.google.devtools.build.lib.actions.SingleStringArgFormatter.isValid;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.devtools.build.lib.testutil.MoreAsserts;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void testFormat() {
assertThat(format("hello %s, hello", "world")).isEqualTo("hello world, hello");
assertThat(format("hello %s, hello", "world")).isEqualTo("hello world, hello");
assertThat(format("hello %%s %s", "world")).isEqualTo("hello %%s world");
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> format("hello", "hello"));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> format("hello %s %s", "hello"));
assertThrows(IllegalArgumentException.class, () -> format("hello", "hello"));
assertThrows(IllegalArgumentException.class, () -> format("hello %s %s", "hello"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.analysis.config;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
Expand All @@ -23,7 +24,6 @@
import com.google.devtools.build.lib.skyframe.trimming.ConfigurationComparer;
import com.google.devtools.build.lib.skyframe.trimming.TrimmableTestConfigurationFragments.AOptions;
import com.google.devtools.build.lib.skyframe.trimming.TrimmableTestConfigurationFragments.BOptions;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import java.util.Objects;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -459,13 +459,13 @@ public void withDifferentBases_throwsError() throws Exception {
OptionsDiffForReconstruction diffB = BuildOptions.diffForReconstruction(baseB, newB);

IllegalArgumentException forwardException =
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> OptionsDiffForReconstruction.compareFragments(diffA, diffB));
assertThat(forwardException).hasMessageThat().contains("diffs with different bases");

IllegalArgumentException reverseException =
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> OptionsDiffForReconstruction.compareFragments(diffB, diffA));
assertThat(reverseException).hasMessageThat().contains("diffs with different bases");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
package com.google.devtools.build.lib.collect.nestedset;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.base.Objects;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.devtools.build.lib.actions.CommandLineItem;
import com.google.devtools.build.lib.actions.CommandLineItem.CapturingMapFn;
import com.google.devtools.build.lib.actions.CommandLineItem.MapFn;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.util.Fingerprint;
import java.util.function.Consumer;
import org.junit.Before;
Expand Down Expand Up @@ -149,14 +149,14 @@ public void testMultipleInstancesOfMapFnThrows() {
// Make sure a ParametrizedMapFn doesn't get blacklisted until it exceeds its instance count
cache.addNestedSetToFingerprint(new IntParametrizedMapFn(1), new Fingerprint(), nestedSet);
cache.addNestedSetToFingerprint(new IntParametrizedMapFn(2), new Fingerprint(), nestedSet);
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() ->
cache.addNestedSetToFingerprint(
new IntParametrizedMapFn(3), new Fingerprint(), nestedSet));

// Make sure a capturing method reference gets blacklisted
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> {
for (int i = 0; i < 2; ++i) {
Expand All @@ -166,7 +166,7 @@ public void testMultipleInstancesOfMapFnThrows() {
});

// Do make sure that a capturing lambda gets blacklisted
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> {
for (int i = 0; i < 2; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
package com.google.devtools.build.lib.collect.nestedset;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -142,10 +142,8 @@ public void testContents() {
public void testSplitFails() {
NestedSet<String> a = NestedSetBuilder.<String>stableOrder().add("a").add("b").build();
NestedSetView<String> v = new NestedSetView<>(a);
MoreAsserts.assertThrows(
IllegalArgumentException.class, () -> v.splitIfExceedsMaximumSize(-100));
MoreAsserts.assertThrows(
IllegalArgumentException.class, () -> v.splitIfExceedsMaximumSize(1));
assertThrows(IllegalArgumentException.class, () -> v.splitIfExceedsMaximumSize(-100));
assertThrows(IllegalArgumentException.class, () -> v.splitIfExceedsMaximumSize(1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.devtools.build.lib.packages.util.PackageFactoryTestBase;
import com.google.devtools.build.lib.syntax.BuildFileAST;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -805,7 +804,7 @@ public void testGlobWithIOErrors() throws Exception {
unreadableSubdir.setReadable(false);

Path file = scratch.file("/pkg/BUILD", "cc_library(name = 'c', srcs = glob(['globs/**']))");
MoreAsserts.assertThrows(
assertThrows(
NoSuchPackageException.class,
() -> packages.eval("pkg", RootedPath.toRootedPath(root, file)));
events.assertContainsError("Directory is not readable");
Expand Down Expand Up @@ -999,7 +998,7 @@ public void testTransientErrorsInGlobbing() throws Exception {
Path parentDir = buildFile.getParentDirectory();
scratch.file("/e/data.txt");
throwOnReaddir = parentDir;
MoreAsserts.assertThrows(
assertThrows(
NoSuchPackageException.class,
() -> packages.createPackage("e", RootedPath.toRootedPath(root, buildFile)));
events.setFailFast(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
Expand Down Expand Up @@ -268,7 +268,7 @@ public void trimFlagValues_withTrimmedFlagsSet_toPopulatedSetPopulatesFlagState(
final BuildOptions testedOptions = options;

FeatureFlagValue.UnknownValueException unknownValueException =
MoreAsserts.assertThrows(
assertThrows(
FeatureFlagValue.UnknownValueException.class,
() -> FeatureFlagValue.getFlagValues(testedOptions));
assertThat(unknownValueException.getUnknownFlags())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package com.google.devtools.build.lib.skyframe.serialization;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
import com.google.devtools.build.lib.skyframe.serialization.testutils.TestUtils;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -49,8 +49,7 @@ public void stackOverflowTransformedIntoSerializationException() {
cur[0] = new Object[1];
cur = (Object[]) cur[0];
}
MoreAsserts.assertThrows(
SerializationException.class, () -> TestUtils.toBytes(obj, ImmutableMap.of()));
assertThrows(SerializationException.class, () -> TestUtils.toBytes(obj, ImmutableMap.of()));
}

private static void verifyDeserialized(Object[] original, Object[] deserialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,7 @@ public void testSkylarkCustomCommandLineKeyComputation() throws Exception {
}

// Ensure errors are handled
MoreAsserts.assertThrows(
assertThrows(
CommandLineExpansionException.class,
() -> {
SkylarkCustomCommandLine commandLine =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
package com.google.devtools.build.lib.unix;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.testing.EqualsTester;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -94,8 +94,8 @@ public void testCrossFilesystemOperationsForbidden() throws Exception {
Path a = unixFs.getPath("/a");
Path b = otherUnixFs.getPath("/b");

MoreAsserts.assertThrows(IllegalArgumentException.class, () -> a.renameTo(b));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> a.relativeTo(b));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> a.createSymbolicLink(b));
assertThrows(IllegalArgumentException.class, () -> a.renameTo(b));
assertThrows(IllegalArgumentException.class, () -> a.relativeTo(b));
assertThrows(IllegalArgumentException.class, () -> a.createSymbolicLink(b));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.io.BaseEncoding;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.unix.FileStatus;
import com.google.devtools.build.lib.unix.NativePosixFiles;
Expand Down Expand Up @@ -519,7 +518,7 @@ public void testCreateDirectoryAndParentsWhenAncestorIsFile() throws IOException
path.getParentDirectory().createDirectoryAndParents();
FileSystemUtils.createEmptyFile(path);
Path theHierarchy = path.getChild("the-hierarchy");
MoreAsserts.assertThrows(IOException.class, theHierarchy::createDirectoryAndParents);
assertThrows(IOException.class, theHierarchy::createDirectoryAndParents);
}

@Test
Expand Down Expand Up @@ -551,7 +550,7 @@ public void testCreateDirectoryAndParentsWhenSymlinkEmbedded() throws IOExceptio
public void testCreateDirectoryAtFileFails() throws Exception {
Path newPath = absolutize("file");
FileSystemUtils.createEmptyFile(newPath);
MoreAsserts.assertThrows(IOException.class, newPath::createDirectoryAndParents);
assertThrows(IOException.class, newPath::createDirectoryAndParents);
}

@Test
Expand Down Expand Up @@ -1153,12 +1152,12 @@ public void testMoveOnNonExistingFileThrowsException() throws Exception {
// Test the Paths
@Test
public void testGetPathOnlyAcceptsAbsolutePath() {
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> testFS.getPath("not-absolute"));
assertThrows(IllegalArgumentException.class, () -> testFS.getPath("not-absolute"));
}

@Test
public void testGetPathOnlyAcceptsAbsolutePathFragment() {
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class, () -> testFS.getPath(PathFragment.create("not-absolute")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static com.google.devtools.build.lib.vfs.PathFragment.create;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.testing.EqualsTester;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import java.io.File;
Expand Down Expand Up @@ -174,12 +174,12 @@ public void testGetChildWorks() {
@Test
public void testGetChildRejectsInvalidBaseNames() {
PathFragment pf = create("../some/path");
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild("."));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild(".."));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild("x/y"));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild("/y"));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild("y/"));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> pf.getChild(""));
assertThrows(IllegalArgumentException.class, () -> pf.getChild("."));
assertThrows(IllegalArgumentException.class, () -> pf.getChild(".."));
assertThrows(IllegalArgumentException.class, () -> pf.getChild("x/y"));
assertThrows(IllegalArgumentException.class, () -> pf.getChild("/y"));
assertThrows(IllegalArgumentException.class, () -> pf.getChild("y/"));
assertThrows(IllegalArgumentException.class, () -> pf.getChild(""));
}

@Test
Expand Down Expand Up @@ -327,14 +327,10 @@ public void testSubFragment() throws Exception {
assertThat(create("foo/bar/baz").subFragment(2).getPathString()).isEqualTo("baz");
assertThat(create("foo/bar/baz").subFragment(3).getPathString()).isEqualTo("");

MoreAsserts.assertThrows(
IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(3, 2));
MoreAsserts.assertThrows(
IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(4, 4));
MoreAsserts.assertThrows(
IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(3, 2));
MoreAsserts.assertThrows(
IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(4));
assertThrows(IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(3, 2));
assertThrows(IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(4, 4));
assertThrows(IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(3, 2));
assertThrows(IndexOutOfBoundsException.class, () -> create("foo/bar/baz").subFragment(4));
}

@Test
Expand Down Expand Up @@ -376,12 +372,12 @@ public void testCheckAllPathsStartWithButAreNotEqualTo() {
PathFragment.checkAllPathsAreUnder(ImmutableList.<PathFragment>of(), create("a"));

// Check fails when some path does not start with startingWithPath:
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> PathFragment.checkAllPathsAreUnder(toPathsSet("a/b", "b/c"), create("a")));

// Check fails when some path is equal to startingWithPath:
MoreAsserts.assertThrows(
assertThrows(
IllegalArgumentException.class,
() -> PathFragment.checkAllPathsAreUnder(toPathsSet("a/b", "a"), create("a")));
}
Expand Down Expand Up @@ -427,14 +423,14 @@ public void testEndsWith() {
public void testToRelative() {
assertThat(create("/foo/bar").toRelative()).isEqualTo(create("foo/bar"));
assertThat(create("/").toRelative()).isEqualTo(create(""));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> create("foo").toRelative());
assertThrows(IllegalArgumentException.class, () -> create("foo").toRelative());
}

@Test
public void testGetDriveStr() {
assertThat(create("/foo/bar").getDriveStr()).isEqualTo("/");
assertThat(create("/").getDriveStr()).isEqualTo("/");
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> create("foo").getDriveStr());
assertThrows(IllegalArgumentException.class, () -> create("foo").getDriveStr());
}

static List<PathFragment> toPaths(List<String> strs) {
Expand Down Expand Up @@ -560,8 +556,8 @@ public void testSegments() {
assertThat(create("/a/b").getSegment(1)).isEqualTo("b");
assertThat(create("/a/b/c").getSegment(2)).isEqualTo("c");

MoreAsserts.assertThrows(IllegalArgumentException.class, () -> create("").getSegment(0));
MoreAsserts.assertThrows(IllegalArgumentException.class, () -> create("a/b").getSegment(2));
assertThrows(IllegalArgumentException.class, () -> create("").getSegment(0));
assertThrows(IllegalArgumentException.class, () -> create("a/b").getSegment(2));
}

@Test
Expand Down
Loading

0 comments on commit b0c7ee5

Please sign in to comment.