diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
13 files changed, 277 insertions, 308 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AnalysisUtilsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AnalysisUtilsTest.java index 821140001f..4c6f2e4e58 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AnalysisUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AnalysisUtilsTest.java @@ -19,7 +19,6 @@ import static com.google.devtools.build.lib.analysis.AnalysisUtils.checkProvider import static org.junit.Assert.fail; import com.google.auto.value.AutoValue; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -38,7 +37,7 @@ public class AnalysisUtilsTest { checkProvider(AutoValue_AnalysisUtilsTest_AutoValuedClass.class); fail("Expected IllegalArgumentException, but nothing was thrown."); } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).contains("generated by @AutoValue"); + assertThat(e).hasMessageThat().contains("generated by @AutoValue"); } } diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java index dedf316868..1928144add 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java @@ -157,7 +157,7 @@ public class HttpConnectorMultiplexerTest { multiplexer.connect(asList(URL1, URL2, URL3), ""); fail("Expected IOException"); } catch (IOException e) { - assertThat(e.getMessage()).contains("All mirrors are down"); + assertThat(e).hasMessageThat().contains("All mirrors are down"); } verify(connector, times(3)).connect(any(URL.class), any(ImmutableMap.class)); verify(sleeper, times(2)).sleepMillis(anyLong()); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java index 8da2e6e0ef..5aa7d107cf 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.bazel.repository.downloader; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableMap; @@ -65,40 +64,40 @@ public class ProxyHelperTest { public void testNoProxy() throws Exception { // Empty address. Proxy proxy = ProxyHelper.createProxy(null); - assertEquals(Proxy.NO_PROXY, proxy); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); proxy = ProxyHelper.createProxy(""); - assertEquals(Proxy.NO_PROXY, proxy); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); Map<String, String> env = ImmutableMap.of(); ProxyHelper helper = new ProxyHelper(env); proxy = helper.createProxyIfNeeded(new URL("https://www.something.com")); - assertEquals(Proxy.NO_PROXY, proxy); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); } @Test public void testProxyDefaultPort() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://my.example.com"); - assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); assertThat(proxy.toString()).endsWith(":80"); - assertEquals("my.example.com", System.getProperty("http.proxyHost")); - assertEquals("80", System.getProperty("http.proxyPort")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("80"); proxy = ProxyHelper.createProxy("https://my.example.com"); assertThat(proxy.toString()).endsWith(":443"); - assertEquals("my.example.com", System.getProperty("https.proxyHost")); - assertEquals("443", System.getProperty("https.proxyPort")); + assertThat(System.getProperty("https.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("https.proxyPort")).isEqualTo("443"); } @Test public void testProxyExplicitPort() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://my.example.com:12345"); assertThat(proxy.toString()).endsWith(":12345"); - assertEquals("my.example.com", System.getProperty("http.proxyHost")); - assertEquals("12345", System.getProperty("http.proxyPort")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("12345"); proxy = ProxyHelper.createProxy("https://my.example.com:12345"); assertThat(proxy.toString()).endsWith(":12345"); - assertEquals("my.example.com", System.getProperty("https.proxyHost")); - assertEquals("12345", System.getProperty("https.proxyPort")); + assertThat(System.getProperty("https.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("https.proxyPort")).isEqualTo("12345"); } @Test @@ -107,7 +106,7 @@ public class ProxyHelperTest { ProxyHelper.createProxy("my.example.com"); fail("Expected protocol error"); } catch (IOException e) { - assertThat(e.getMessage()).contains("Proxy address my.example.com is not a valid URL"); + assertThat(e).hasMessageThat().contains("Proxy address my.example.com is not a valid URL"); } } @@ -117,7 +116,9 @@ public class ProxyHelperTest { ProxyHelper.createProxy("my.example.com:12345"); fail("Expected protocol error"); } catch (IOException e) { - assertThat(e.getMessage()).contains("Proxy address my.example.com:12345 is not a valid URL"); + assertThat(e) + .hasMessageThat() + .contains("Proxy address my.example.com:12345 is not a valid URL"); } } @@ -127,7 +128,8 @@ public class ProxyHelperTest { ProxyHelper.createProxy("http://my.example.com:foo"); fail("Should have thrown an error for invalid port"); } catch (IOException e) { - assertThat(e.getMessage()) + assertThat(e) + .hasMessageThat() .contains("Proxy address http://my.example.com:foo is not a valid URL"); } } @@ -135,30 +137,30 @@ public class ProxyHelperTest { @Test public void testProxyAuth() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://foo:barbaz@my.example.com"); - assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); assertThat(proxy.toString()).endsWith(":80"); - assertEquals("my.example.com", System.getProperty("http.proxyHost")); - assertEquals("80", System.getProperty("http.proxyPort")); - assertEquals("foo", System.getProperty("http.proxyUser")); - assertEquals("barbaz", System.getProperty("http.proxyPassword")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("80"); + assertThat(System.getProperty("http.proxyUser")).isEqualTo("foo"); + assertThat(System.getProperty("http.proxyPassword")).isEqualTo("barbaz"); proxy = ProxyHelper.createProxy("https://biz:bat@my.example.com"); assertThat(proxy.toString()).endsWith(":443"); - assertEquals("my.example.com", System.getProperty("https.proxyHost")); - assertEquals("443", System.getProperty("https.proxyPort")); - assertEquals("biz", System.getProperty("https.proxyUser")); - assertEquals("bat", System.getProperty("https.proxyPassword")); + assertThat(System.getProperty("https.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("https.proxyPort")).isEqualTo("443"); + assertThat(System.getProperty("https.proxyUser")).isEqualTo("biz"); + assertThat(System.getProperty("https.proxyPassword")).isEqualTo("bat"); } @Test public void testEncodedProxyAuth() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://foo:b%40rb%40z@my.example.com"); - assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); assertThat(proxy.toString()).endsWith(":80"); - assertEquals("my.example.com", System.getProperty("http.proxyHost")); - assertEquals("80", System.getProperty("http.proxyPort")); - assertEquals("foo", System.getProperty("http.proxyUser")); - assertEquals("b@rb@z", System.getProperty("http.proxyPassword")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("my.example.com"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("80"); + assertThat(System.getProperty("http.proxyUser")).isEqualTo("foo"); + assertThat(System.getProperty("http.proxyPassword")).isEqualTo("b@rb@z"); } @Test @@ -167,27 +169,27 @@ public class ProxyHelperTest { ProxyHelper.createProxy("http://foo@my.example.com"); fail("Should have thrown an error for invalid auth"); } catch (IOException e) { - assertThat(e.getMessage()).contains("No password given for proxy"); + assertThat(e).hasMessageThat().contains("No password given for proxy"); } } @Test public void testNoProxyAuth() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://localhost:3128/"); - assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); assertThat(proxy.toString()).endsWith(":3128"); - assertEquals("localhost", System.getProperty("http.proxyHost")); - assertEquals("3128", System.getProperty("http.proxyPort")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("localhost"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("3128"); } @Test public void testTrailingSlash() throws Exception { Proxy proxy = ProxyHelper.createProxy("http://foo:bar@example.com:8000/"); - assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.type()).isEqualTo(Proxy.Type.HTTP); assertThat(proxy.toString()).endsWith(":8000"); - assertEquals("example.com", System.getProperty("http.proxyHost")); - assertEquals("8000", System.getProperty("http.proxyPort")); - assertEquals("foo", System.getProperty("http.proxyUser")); - assertEquals("bar", System.getProperty("http.proxyPassword")); + assertThat(System.getProperty("http.proxyHost")).isEqualTo("example.com"); + assertThat(System.getProperty("http.proxyPort")).isEqualTo("8000"); + assertThat(System.getProperty("http.proxyUser")).isEqualTo("foo"); + assertThat(System.getProperty("http.proxyPassword")).isEqualTo("bar"); } } diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java index 8f99efca83..c7ef2181a7 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java @@ -15,8 +15,6 @@ package com.google.devtools.build.lib.buildeventstream.transports; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; @@ -103,7 +101,7 @@ public class BinaryFormatFileTransportTest { // Get a file that doesn't exist by creating a new file and immediately deleting it. File output = tmp.newFile(); String path = output.getAbsolutePath(); - assertTrue(output.delete()); + assertThat(output.delete()).isTrue(); BuildEventStreamProtos.BuildEvent started = BuildEventStreamProtos.BuildEvent.newBuilder() @@ -135,7 +133,7 @@ public class BinaryFormatFileTransportTest { // Close the file. transport.ch.close(); - assertFalse(transport.ch.isOpen()); + assertThat(transport.ch.isOpen()).isFalse(); // This should not throw an exception. transport.sendBuildEvent(buildEvent, artifactGroupNamer); @@ -166,7 +164,7 @@ public class BinaryFormatFileTransportTest { transport.sendBuildEvent(buildEvent, artifactGroupNamer); closeFuture.get(); - assertFalse(transport.ch.isOpen()); + assertThat(transport.ch.isOpen()).isFalse(); // There should have only been one write. try (InputStream in = new FileInputStream(output)) { diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java index 1633111cea..60c056f42b 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java @@ -13,11 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.pkgcache; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; @@ -145,7 +141,7 @@ public class BuildFileModificationTest extends FoundationTestCase { Path build = scratch.file( "a/BUILD", "cc_library(name='a', feet='stinky')".getBytes(StandardCharsets.ISO_8859_1)); Package a1 = getPackage("a"); - assertTrue(a1.containsErrors()); + assertThat(a1.containsErrors()).isTrue(); assertContainsEvent("//a:a: no such attribute 'feet'"); eventCollector.clear(); // writeContent updates mtime and ctime. Note that we keep the content length exactly the same. @@ -155,8 +151,8 @@ public class BuildFileModificationTest extends FoundationTestCase { invalidatePackages(); Package a2 = getPackage("a"); - assertNotSame(a1, a2); - assertFalse(a2.containsErrors()); + assertThat(a2).isNotSameAs(a1); + assertThat(a2.containsErrors()).isFalse(); assertNoEvents(); } @@ -170,13 +166,14 @@ public class BuildFileModificationTest extends FoundationTestCase { clock.advanceMillis(1); FileSystemUtils.writeContent( path, "cc_library(name = 'bar')\n".getBytes(StandardCharsets.ISO_8859_1)); - assertSame(oldPkg, getPackage("pkg")); // Change only becomes visible after invalidatePackages. + assertThat(getPackage("pkg")) + .isSameAs(oldPkg); // Change only becomes visible after invalidatePackages. invalidatePackages(); Package newPkg = getPackage("pkg"); - assertNotSame(oldPkg, newPkg); - assertNotNull(newPkg.getTarget("bar")); + assertThat(newPkg).isNotSameAs(oldPkg); + assertThat(newPkg.getTarget("bar")).isNotNull(); } @Test @@ -193,7 +190,7 @@ public class BuildFileModificationTest extends FoundationTestCase { invalidatePackages(); Package a2 = getPackage("a"); - assertNotSame(a1, a2); + assertThat(a2).isNotSameAs(a1); assertNoEvents(); } @@ -206,11 +203,11 @@ public class BuildFileModificationTest extends FoundationTestCase { // Change ctime to 1. clock.advanceMillis(1); path.setLastModifiedTime(1001); - assertSame(oldPkg, getPackage("pkg")); // change not yet visible + assertThat(getPackage("pkg")).isSameAs(oldPkg); // change not yet visible invalidatePackages(); Package newPkg = getPackage("pkg"); - assertNotSame(oldPkg, newPkg); + assertThat(newPkg).isNotSameAs(oldPkg); } } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformerTest.java index 7ac30babb6..d421e9229c 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformerTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformerTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.pkgcache; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import com.google.devtools.build.lib.cmdline.Label; @@ -106,7 +105,7 @@ public class CompileOneDependencyTransformerTest extends PackageLoadingTestCase } private static Set<Target> getFailFast(ResolvedTargets<Target> result) { - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); return result.getTargets(); } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java index 6472f01279..3cbcf24a36 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java @@ -13,8 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.pkgcache; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Function; import com.google.devtools.build.lib.cmdline.Label; @@ -105,7 +104,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase { return null; } }; - assertFalse(visitTransitively(Label.parseAbsolute("//pkg:x"))); + assertThat(visitTransitively(Label.parseAbsolute("//pkg:x"))).isFalse(); scratch.overwriteFile("pkg/BUILD", "# another comment to force reload", "sh_library(name = 'x')"); @@ -113,7 +112,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase { syncPackages(); eventCollector.clear(); reporter.addHandler(failFastHandler); - assertTrue(visitTransitively(Label.parseAbsolute("//pkg:x"))); + assertThat(visitTransitively(Label.parseAbsolute("//pkg:x"))).isTrue(); assertNoEvents(); } @@ -134,7 +133,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase { return null; } }; - assertFalse(visitTransitively(Label.parseAbsolute("//top:top"))); + assertThat(visitTransitively(Label.parseAbsolute("//top:top"))).isFalse(); assertContainsEvent("no such package 'pkg'"); // The traditional label visitor does not propagate the original IOException message. // assertContainsEvent("custom crash"); @@ -148,7 +147,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase { syncPackages(); eventCollector.clear(); reporter.addHandler(failFastHandler); - assertTrue(visitTransitively(Label.parseAbsolute("//top:top"))); + assertThat(visitTransitively(Label.parseAbsolute("//top:top"))).isTrue(); assertNoEvents(); } @@ -167,6 +166,6 @@ public class IOExceptionsTest extends PackageLoadingTestCase { return null; } }; - assertFalse(visitTransitively(Label.parseAbsolute("//top/pkg:x"))); + assertThat(visitTransitively(Label.parseAbsolute("//top/pkg:x"))).isFalse(); } } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java index 3b7908e74d..aad829ecd1 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java @@ -14,11 +14,6 @@ package com.google.devtools.build.lib.pkgcache; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Predicates; @@ -192,7 +187,7 @@ public class PackageCacheTest extends FoundationTestCase { getPackage(packageName); fail(); } catch (NoSuchPackageException e) { - assertThat(e.getMessage()).contains(expectedMessage); + assertThat(e).hasMessageThat().contains(expectedMessage); } } @@ -200,11 +195,10 @@ public class PackageCacheTest extends FoundationTestCase { public void testGetPackage() throws Exception { createPkg1(); Package pkg1 = getPackage("pkg1"); - assertEquals("pkg1", pkg1.getName()); - assertEquals("/workspace/pkg1/BUILD", - pkg1.getFilename().toString()); - assertSame(pkg1, getPackageManager().getPackage(reporter, - PackageIdentifier.createInMainRepo("pkg1"))); + assertThat(pkg1.getName()).isEqualTo("pkg1"); + assertThat(pkg1.getFilename().toString()).isEqualTo("/workspace/pkg1/BUILD"); + assertThat(getPackageManager().getPackage(reporter, PackageIdentifier.createInMainRepo("pkg1"))) + .isSameAs(pkg1); } @Test @@ -234,7 +228,7 @@ public class PackageCacheTest extends FoundationTestCase { createPkg1(); Label label = Label.parseAbsolute("//pkg1:foo"); Target target = getTarget(label); - assertEquals(label, target.getLabel()); + assertThat(target.getLabel()).isEqualTo(label); } @Test @@ -278,7 +272,7 @@ public class PackageCacheTest extends FoundationTestCase { // Found: Package missing = getPackage("missing"); - assertEquals("missing", missing.getName()); + assertThat(missing.getName()).isEqualTo("missing"); } /** @@ -305,7 +299,7 @@ public class PackageCacheTest extends FoundationTestCase { getPackage("broken"); fail(); } catch (BuildFileContainsErrorsException e) { - assertThat(e.getMessage()).contains("/workspace/broken/BUILD (Permission denied)"); + assertThat(e).hasMessageThat().contains("/workspace/broken/BUILD (Permission denied)"); } eventCollector.clear(); @@ -316,7 +310,7 @@ public class PackageCacheTest extends FoundationTestCase { invalidatePackages(); // resets cache of failures Package broken = getPackage("broken"); - assertEquals("broken", broken.getName()); + assertThat(broken.getName()).isEqualTo("broken"); assertNoEvents(); } @@ -329,17 +323,17 @@ public class PackageCacheTest extends FoundationTestCase { setOptions("--package_path=/workspace:/otherroot"); Package oldPkg = getPackage("pkg"); - assertSame(oldPkg, getPackage("pkg")); // change not yet visible - assertEquals(buildFile1, oldPkg.getFilename()); - assertEquals(rootDirectory, oldPkg.getSourceRoot()); + assertThat(getPackage("pkg")).isSameAs(oldPkg); // change not yet visible + assertThat(oldPkg.getFilename()).isEqualTo(buildFile1); + assertThat(oldPkg.getSourceRoot()).isEqualTo(rootDirectory); buildFile1.delete(); invalidatePackages(); Package newPkg = getPackage("pkg"); - assertNotSame(oldPkg, newPkg); - assertEquals(buildFile2, newPkg.getFilename()); - assertEquals(scratch.dir("/otherroot"), newPkg.getSourceRoot()); + assertThat(newPkg).isNotSameAs(oldPkg); + assertThat(newPkg.getFilename()).isEqualTo(buildFile2); + assertThat(newPkg.getSourceRoot()).isEqualTo(scratch.dir("/otherroot")); // TODO(bazel-team): (2009) test BUILD file moves in the other direction too. } @@ -412,7 +406,7 @@ public class PackageCacheTest extends FoundationTestCase { private void assertPackageLoadingFails(String pkgName, String expectedError) throws Exception { Package pkg = getPackage(pkgName); - assertTrue(pkg.containsErrors()); + assertThat(pkg.containsErrors()).isTrue(); assertContainsEvent(expectedError); } @@ -425,7 +419,7 @@ public class PackageCacheTest extends FoundationTestCase { reporter.removeHandler(failFastHandler); List<Event> events = getPackage("e").getEvents(); assertThat(events).hasSize(1); - assertEquals(2, events.get(0).getLocation().getStartLineAndColumn().getLine()); + assertThat(events.get(0).getLocation().getStartLineAndColumn().getLine()).isEqualTo(2); } /** Static tests (i.e. no changes to filesystem, nor calls to sync). */ @@ -501,8 +495,7 @@ public class PackageCacheTest extends FoundationTestCase { // root. It's as if we've merged c and c/d in the first root. // c/d is still a subpackage--found in the second root: - assertEquals(rootDir2.getRelative("c/d/BUILD"), - getPackage("c/d").getFilename()); + assertThat(getPackage("c/d").getFilename()).isEqualTo(rootDir2.getRelative("c/d/BUILD")); // Subpackage labels are still valid... assertLabelValidity(true, "//c/d:foo.txt"); @@ -512,14 +505,14 @@ public class PackageCacheTest extends FoundationTestCase { "Label '//c:d/x' crosses boundary of subpackage 'c/d' (have you deleted c/d/BUILD? " + "If so, use the --deleted_packages=c/d option)"); - assertTrue(getPackageManager().isPackage( - reporter, PackageIdentifier.createInMainRepo("c/d"))); + assertThat(getPackageManager().isPackage(reporter, PackageIdentifier.createInMainRepo("c/d"))) + .isTrue(); setOptions("--deleted_packages=c/d"); invalidatePackages(); - assertFalse(getPackageManager().isPackage( - reporter, PackageIdentifier.createInMainRepo("c/d"))); + assertThat(getPackageManager().isPackage(reporter, PackageIdentifier.createInMainRepo("c/d"))) + .isFalse(); // c/d is no longer a subpackage--even though there's a BUILD file in the // second root: @@ -557,6 +550,6 @@ public class PackageCacheTest extends FoundationTestCase { "outs = ['y/z.h'],", "cmd = '')"); Package p = getPackage("x"); - assertTrue(p.containsErrors()); + assertThat(p.containsErrors()).isTrue(); } } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java index 5cf6ada07b..f7d1aa44db 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java @@ -14,9 +14,6 @@ package com.google.devtools.build.lib.pkgcache; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -182,54 +179,58 @@ public class PathPackageLocatorTest extends FoundationTestCase { @Test public void testGetPackageBuildFile() throws Exception { AtomicReference<? extends UnixGlob.FilesystemCalls> cache = UnixGlob.DEFAULT_SYSCALLS_REF; - assertEquals(buildFile_1A, locator.getPackageBuildFile( - PackageIdentifier.createInMainRepo("A"))); - assertEquals(buildFile_1A, locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("A"), cache)); - assertEquals(buildFile_1B, locator.getPackageBuildFile( - PackageIdentifier.createInMainRepo("B"))); - assertEquals(buildFile_1B, locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("B"), cache)); - assertEquals(buildFile_2C, locator.getPackageBuildFile( - PackageIdentifier.createInMainRepo("C"))); - assertEquals(buildFile_2C, locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("C"), cache)); - assertEquals(buildFile_2CD, locator.getPackageBuildFile( - PackageIdentifier.createInMainRepo("C/D"))); - assertEquals(buildFile_2CD, locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("C/D"), cache)); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("A"))) + .isEqualTo(buildFile_1A); + assertThat(locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("A"), cache)) + .isEqualTo(buildFile_1A); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("B"))) + .isEqualTo(buildFile_1B); + assertThat(locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("B"), cache)) + .isEqualTo(buildFile_1B); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("C"))) + .isEqualTo(buildFile_2C); + assertThat(locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("C"), cache)) + .isEqualTo(buildFile_2C); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("C/D"))) + .isEqualTo(buildFile_2CD); + assertThat( + locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("C/D"), cache)) + .isEqualTo(buildFile_2CD); checkFails("C/E", "no such package 'C/E': BUILD file not found on package path"); - assertNull(locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("C/E"), cache)); - assertEquals(buildFile_2F, - locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("F"))); + assertThat( + locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("C/E"), cache)) + .isNull(); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("F"))) + .isEqualTo(buildFile_2F); checkFails("F/G", "no such package 'F/G': BUILD file not found on package path"); - assertNull(locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("F/G"), cache)); - assertEquals(buildFile_2FGH, locator.getPackageBuildFile( - PackageIdentifier.createInMainRepo("F/G/H"))); - assertEquals(buildFile_2FGH, locator.getPackageBuildFileNullable( - PackageIdentifier.createInMainRepo("F/G/H"), cache)); + assertThat( + locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("F/G"), cache)) + .isNull(); + assertThat(locator.getPackageBuildFile(PackageIdentifier.createInMainRepo("F/G/H"))) + .isEqualTo(buildFile_2FGH); + assertThat( + locator.getPackageBuildFileNullable(PackageIdentifier.createInMainRepo("F/G/H"), cache)) + .isEqualTo(buildFile_2FGH); checkFails("I", "no such package 'I': BUILD file not found on package path"); } @Test public void testGetPackageBuildFileWithSymlinks() throws Exception { - assertEquals(buildFile_3A, locatorWithSymlinks.getPackageBuildFile( - PackageIdentifier.createInMainRepo("A"))); - assertEquals(buildFile_3B, locatorWithSymlinks.getPackageBuildFile( - PackageIdentifier.createInMainRepo("B"))); - assertEquals(buildFile_3CI, locatorWithSymlinks.getPackageBuildFile( - PackageIdentifier.createInMainRepo("C/I"))); + assertThat(locatorWithSymlinks.getPackageBuildFile(PackageIdentifier.createInMainRepo("A"))) + .isEqualTo(buildFile_3A); + assertThat(locatorWithSymlinks.getPackageBuildFile(PackageIdentifier.createInMainRepo("B"))) + .isEqualTo(buildFile_3B); + assertThat(locatorWithSymlinks.getPackageBuildFile(PackageIdentifier.createInMainRepo("C/I"))) + .isEqualTo(buildFile_3CI); checkFails( locatorWithSymlinks, "C/D", "no such package 'C/D': BUILD file not found on package path"); } @Test public void testGetWorkspaceFile() throws Exception { - assertEquals(rootDir1WorkspaceFile, locator.getWorkspaceFile()); + assertThat(locator.getWorkspaceFile()).isEqualTo(rootDir1WorkspaceFile); } private Path setLocator(String root) { @@ -286,11 +287,11 @@ public class PathPackageLocatorTest extends FoundationTestCase { // No warning if workspace == cwd. PathPackageLocator.create(null, ImmutableList.of("./foo"), reporter, workspace, workspace); - assertSame(0, eventCollector.count()); + assertThat(eventCollector.count()).isSameAs(0); PathPackageLocator.create( null, ImmutableList.of("./foo"), reporter, workspace, workspace.getRelative("foo")); - assertSame(1, eventCollector.count()); + assertThat(eventCollector.count()).isSameAs(1); assertContainsEvent("The package path element './foo' will be taken relative"); } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java index da003add73..7f7376c5f3 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java @@ -15,10 +15,6 @@ package com.google.devtools.build.lib.pkgcache; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.pkgcache.FilteringPolicies.FILTER_TESTS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -36,15 +32,13 @@ import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; - +import java.util.Arrays; +import java.util.Set; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.Arrays; -import java.util.Set; - /** Tests for {@link TargetPatternEvaluator}. */ @RunWith(JUnit4.class) public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTest { @@ -170,7 +164,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe throws TargetParsingException, InterruptedException { ResolvedTargets<Target> result = parseTargetPatternList(parser, parsingListener, Arrays.asList(patterns), true); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); return targetsToLabels(result.getTargets()); } @@ -188,7 +182,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe } private static Set<Target> getFailFast(ResolvedTargets<Target> result) { - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); return result.getTargets(); } @@ -198,7 +192,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe parser.parseTargetPattern(parsingListener, target, false); fail("target='" + target + "', expected error: " + expectedError); } catch (TargetParsingException e) { - assertThat(e.getMessage()).contains(expectedError); + assertThat(e).hasMessageThat().contains(expectedError); } } @@ -224,14 +218,13 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testParsingStandardLabel() throws Exception { - assertEquals("//foo:foo1", - parseIndividualTarget("//foo:foo1").toString()); + assertThat(parseIndividualTarget("//foo:foo1").toString()).isEqualTo("//foo:foo1"); } @Test public void testAbsolutePatternEndsWithSlashAll() throws Exception { scratch.file("foo/all/BUILD", "cc_library(name = 'all')"); - assertEquals("//foo/all:all", parseIndividualTarget("//foo/all").toString()); + assertThat(parseIndividualTarget("//foo/all").toString()).isEqualTo("//foo/all:all"); assertNoEvents(); } @@ -249,8 +242,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe } private void assertWildcardConflict(String label, String suffix) throws Exception { - assertEquals(label, parseIndividualTarget(label).toString()); - assertSame(1, eventCollector.count()); + assertThat(parseIndividualTarget(label).toString()).isEqualTo(label); + assertThat(eventCollector.count()).isSameAs(1); assertContainsEvent(String.format("The target pattern '%s' is ambiguous: '%s' is both " + "a wildcard, and the name of an existing cc_library rule; " + "using the latter interpretation", label, suffix)); @@ -262,13 +255,13 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe parseIndividualTarget("//missing:foo1"); fail("TargetParsingException expected"); } catch (TargetParsingException e) { - assertThat(e.getMessage()).startsWith("no such package"); + assertThat(e).hasMessageThat().startsWith("no such package"); } } @Test public void testParsingStandardLabelWithRelativeParser() throws Exception { - assertEquals("//foo:foo1", parseIndividualTargetRelative("//foo:foo1").toString()); + assertThat(parseIndividualTargetRelative("//foo:foo1").toString()).isEqualTo("//foo:foo1"); } @Test @@ -277,19 +270,18 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe parseIndividualTarget("//foo:missing"); fail("TargetParsingException expected"); } catch (TargetParsingException e) { - assertThat(e.getMessage()).startsWith("no such target"); + assertThat(e).hasMessageThat().startsWith("no such target"); } } @Test public void testParsingStandardLabelShorthand() throws Exception { - assertEquals("//foo:foo1", - parseIndividualTarget("foo:foo1").toString()); + assertThat(parseIndividualTarget("foo:foo1").toString()).isEqualTo("//foo:foo1"); } @Test public void testParsingStandardLabelShorthandRelative() throws Exception { - assertEquals("//foo:foo1", parseIndividualTargetRelative(":foo1").toString()); + assertThat(parseIndividualTargetRelative(":foo1").toString()).isEqualTo("//foo:foo1"); } @Test @@ -477,8 +469,10 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe public void testDefaultPackage() throws Exception { scratch.file("experimental/BUILD", "cc_library(name = 'experimental', srcs = [ 'experimental.cc' ])"); - assertEquals("//experimental:experimental", parseIndividualTarget("//experimental").toString()); - assertEquals("//experimental:experimental", parseIndividualTarget("experimental").toString()); + assertThat(parseIndividualTarget("//experimental").toString()) + .isEqualTo("//experimental:experimental"); + assertThat(parseIndividualTarget("experimental").toString()) + .isEqualTo("//experimental:experimental"); assertNoEvents(); } @@ -491,28 +485,26 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("sub/dir/BUILD", "exports_files(['dir2'])"); scratch.file("sub/dir/dir/BUILD", "exports_files(['dir'])"); // sub/dir/dir is a package - assertEquals("//sub/dir/dir:dir", parseIndividualTarget("sub/dir/dir").toString()); + assertThat(parseIndividualTarget("sub/dir/dir").toString()).isEqualTo("//sub/dir/dir:dir"); // sub/dir is a package but not sub/dir/dir2 - assertEquals("//sub/dir:dir2", parseIndividualTarget("sub/dir/dir2").toString()); + assertThat(parseIndividualTarget("sub/dir/dir2").toString()).isEqualTo("//sub/dir:dir2"); // sub is a package but not sub/dir2 - assertEquals("//sub:dir2/dir2", parseIndividualTarget("sub/dir2/dir2").toString()); + assertThat(parseIndividualTarget("sub/dir2/dir2").toString()).isEqualTo("//sub:dir2/dir2"); } @Test public void testFindsLongestPlausiblePackageName() throws Exception { - assertEquals("//foo/bar:baz", - parseIndividualTarget("foo/bar/baz").toString()); - assertEquals("//foo/bar:baz/bang", - parseIndividualTarget("foo/bar/baz/bang").toString()); - assertEquals("//foo:baz/bang", - parseIndividualTarget("foo/baz/bang").toString()); + assertThat(parseIndividualTarget("foo/bar/baz").toString()).isEqualTo("//foo/bar:baz"); + assertThat(parseIndividualTarget("foo/bar/baz/bang").toString()) + .isEqualTo("//foo/bar:baz/bang"); + assertThat(parseIndividualTarget("foo/baz/bang").toString()).isEqualTo("//foo:baz/bang"); } @Test public void testParsesIterableOfLabels() throws Exception { Set<Label> labels = Sets.newHashSet(Label.parseAbsolute("//foo/bar:bar1"), Label.parseAbsolute("//foo:foo1")); - assertEquals(labels, parseList("//foo/bar:bar1", "//foo:foo1")); + assertThat(parseList("//foo/bar:bar1", "//foo:foo1")).isEqualTo(labels); parsingListener.assertEmpty(); } @@ -520,24 +512,23 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe public void testParseAbsoluteWithRelativeParser() throws Exception { Set<Label> labels = Sets.newHashSet(Label.parseAbsolute("//foo/bar:bar1"), Label.parseAbsolute("//foo:foo1")); - assertEquals(labels, parseListRelative("//foo/bar:bar1", "//foo:foo1")); + assertThat(parseListRelative("//foo/bar:bar1", "//foo:foo1")).isEqualTo(labels); parsingListener.assertEmpty(); } @Test public void testMultisegmentLabelsWithNoSlashSlash() throws Exception { - assertEquals("//foo/bar:wiz/bang", - parseIndividualTarget("foo/bar:wiz/bang").toString()); - assertEquals("//foo/bar:wiz/all", - parseIndividualTarget("foo/bar:wiz/all").toString()); + assertThat(parseIndividualTarget("foo/bar:wiz/bang").toString()) + .isEqualTo("//foo/bar:wiz/bang"); + assertThat(parseIndividualTarget("foo/bar:wiz/all").toString()).isEqualTo("//foo/bar:wiz/all"); } @Test public void testMultisegmentLabelsWithNoSlashSlashRelative() throws Exception { - assertEquals("//foo/bar:wiz/bang", - parseIndividualTargetRelative("bar:wiz/bang").toString()); - assertEquals("//foo/bar:wiz/all", - parseIndividualTargetRelative("bar:wiz/all").toString()); + assertThat(parseIndividualTargetRelative("bar:wiz/bang").toString()) + .isEqualTo("//foo/bar:wiz/bang"); + assertThat(parseIndividualTargetRelative("bar:wiz/all").toString()) + .isEqualTo("//foo/bar:wiz/all"); } /** Regression test for a bug. */ @@ -546,8 +537,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("x/y/BUILD", "cc_library(name='y')"); scratch.file("x/z/BUILD", "cc_library(name='z')"); setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); - assertEquals(Sets.newHashSet(Label.parseAbsolute("//x/z")), - parseList("x/...")); + assertThat(parseList("x/...")).isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z"))); } @Test @@ -557,8 +547,9 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); parser.updateOffset(PathFragment.create("x")); - assertEquals(Sets.newHashSet(Label.parseAbsolute("//x/z")), - targetsToLabels(getFailFast(parser.parseTargetPattern(parsingListener, "...", false)))); + assertThat( + targetsToLabels(getFailFast(parser.parseTargetPattern(parsingListener, "...", false)))) + .isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z"))); } @Test @@ -566,15 +557,15 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("x/y/BUILD", "cc_library(name='y')"); scratch.file("x/z/BUILD", "cc_library(name='z')"); - assertEquals(Sets.newHashSet(Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")), - parseList("x/...")); + assertThat(parseList("x/...")).containsExactly( + Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")); setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); - assertEquals(Sets.newHashSet(Label.parseAbsolute("//x/z")), parseList("x/...")); + assertThat(parseList("x/...")).containsExactly(Label.parseAbsolute("//x/z")); setDeletedPackages(ImmutableSet.<PackageIdentifier>of()); - assertEquals(Sets.newHashSet(Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")), - parseList("x/...")); + assertThat(parseList("x/...")).containsExactly( + Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")); } @Test @@ -784,10 +775,10 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testSetOffset() throws Exception { - assertEquals("//foo:foo1", parseIndividualTarget("foo:foo1").toString()); + assertThat(parseIndividualTarget("foo:foo1").toString()).isEqualTo("//foo:foo1"); parser.updateOffset(PathFragment.create("foo")); - assertEquals("//foo:foo1", parseIndividualTarget(":foo1").toString()); + assertThat(parseIndividualTarget(":foo1").toString()).isEqualTo("//foo:foo1"); } @Test @@ -847,7 +838,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe assertThat(result.first) .containsExactlyElementsIn( Sets.newHashSet(Label.parseAbsolute("//x/y:a"), Label.parseAbsolute("//x/y:b"))); - assertFalse(result.second); + assertThat(result.second).isFalse(); } @Test @@ -883,7 +874,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe // Even though there was a loading error in the package, parsing the target pattern was // successful. - assertFalse(result.second); + assertThat(result.second).isFalse(); } @Test @@ -901,7 +892,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe /*keepGoing=*/false); fail(); } catch (TargetParsingException e) { - assertThat(e.getMessage()).contains("no such target"); + assertThat(e).hasMessageThat().contains("no such target"); } } @@ -910,13 +901,12 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe ResolvedTargets<Target> result = parseTargetPatternList(parser, parsingListener, Arrays.asList("//foo/bar/BUILD"), false); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertThat(result.getTargets()).hasSize(1); Label label = Iterables.getOnlyElement(result.getTargets()).getLabel(); - assertEquals("BUILD", label.getName()); - assertEquals("foo/bar", label.getPackageName()); - + assertThat(label.getName()).isEqualTo("BUILD"); + assertThat(label.getPackageName()).isEqualTo("foo/bar"); } /** @@ -933,9 +923,9 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe "genrule(name='c', outs=['c.out'])"); Pair<Set<Label>, Boolean> result = parseListKeepGoing("//loading:y"); - assertEquals(Label.parseAbsolute("//loading:y"), Iterables.getOnlyElement(result.first)); + assertThat(result.first).containsExactly(Label.parseAbsolute("//loading:y")); assertContainsEvent("missing value for mandatory attribute"); - assertFalse(result.second); + assertThat(result.second).isFalse(); } private void assertKeepGoing(Set<Label> expectedLabels, String expectedEvent, String... toParse) diff --git a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java index 1c343b27bd..7292378a2a 100644 --- a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java +++ b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java @@ -14,9 +14,6 @@ package com.google.devtools.build.lib.profiler; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; import com.google.devtools.build.lib.profiler.Profiler.ProfiledTaskKinds; import com.google.devtools.build.lib.profiler.chart.AggregatingChartCreator; @@ -36,16 +33,12 @@ import com.google.devtools.build.lib.testutil.Suite; import com.google.devtools.build.lib.testutil.TestSpec; import com.google.devtools.build.lib.util.BlazeClock; import com.google.devtools.build.lib.vfs.Path; - +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.List; - -/** - * Unit tests for the profiler chart generation. - */ +/** Unit tests for the profiler chart generation. */ @TestSpec(size = Suite.MEDIUM_TESTS) @RunWith(JUnit4.class) public class ProfilerChartTest extends FoundationTestCase { @@ -67,13 +60,13 @@ public class ProfilerChartTest extends FoundationTestCase { ProfileInfo info = createProfileInfo(run, threads - 1); ChartCreator aggregatingCreator = new AggregatingChartCreator(info, true); Chart aggregatedChart = aggregatingCreator.create(); - assertEquals(threads, aggregatedChart.getRowCount()); + assertThat(aggregatedChart.getRowCount()).isEqualTo(threads); assertThat(aggregatedChart.getSortedRows().get(0).getBars()).hasSize(1); ChartCreator detailedCreator = new DetailedChartCreator(info); Chart detailedChart = detailedCreator.create(); assertThat(detailedChart.getSortedTypes()).hasSize(COMMON_CHART_TYPES + DETAILED_CHART_TYPES); - assertEquals(threads, detailedChart.getRowCount()); + assertThat(detailedChart.getRowCount()).isEqualTo(threads); assertThat(detailedChart.getSortedRows().get(0).getBars()).hasSize(1); } @@ -123,18 +116,18 @@ public class ProfilerChartTest extends FoundationTestCase { ChartBarType type1 = chart.createType("name1", Color.BLACK); List<ChartBarType> types = chart.getSortedTypes(); assertThat(types).hasSize(3); - assertEquals(type1.getName(), types.get(0).getName()); - assertEquals(type1.getColor(), types.get(0).getColor()); - assertEquals(type2.getName(), types.get(1).getName()); - assertEquals(type2.getColor(), types.get(1).getColor()); - assertEquals(type3.getName(), types.get(2).getName()); - assertEquals(type3.getColor(), types.get(2).getColor()); - - assertSame(type3, chart.lookUpType("name3")); - assertSame(type2, chart.lookUpType("name2")); - assertSame(type1, chart.lookUpType("name1")); - - assertSame(Chart.UNKNOWN_TYPE, chart.lookUpType("wergl")); + assertThat(types.get(0).getName()).isEqualTo(type1.getName()); + assertThat(types.get(0).getColor()).isEqualTo(type1.getColor()); + assertThat(types.get(1).getName()).isEqualTo(type2.getName()); + assertThat(types.get(1).getColor()).isEqualTo(type2.getColor()); + assertThat(types.get(2).getName()).isEqualTo(type3.getName()); + assertThat(types.get(2).getColor()).isEqualTo(type3.getColor()); + + assertThat(chart.lookUpType("name3")).isSameAs(type3); + assertThat(chart.lookUpType("name2")).isSameAs(type2); + assertThat(chart.lookUpType("name1")).isSameAs(type1); + + assertThat(chart.lookUpType("wergl")).isSameAs(Chart.UNKNOWN_TYPE); types = chart.getSortedTypes(); assertThat(types).hasSize(4); @@ -145,8 +138,8 @@ public class ProfilerChartTest extends FoundationTestCase { chart.addBar(3, 4, 5, type3, "label5"); chart.addBar(3, 5, 6, type3, "label6"); - assertEquals(6, chart.getMaxStop()); - assertEquals(3, chart.getRowCount()); + assertThat(chart.getMaxStop()).isEqualTo(6); + assertThat(chart.getRowCount()).isEqualTo(3); List<ChartRow> rows = chart.getSortedRows(); assertThat(rows).hasSize(3); @@ -155,10 +148,10 @@ public class ProfilerChartTest extends FoundationTestCase { assertThat(rows.get(2).getBars()).hasSize(3); ChartBar bar = rows.get(0).getBars().get(0); - assertEquals(2, bar.getStart()); - assertEquals(3, bar.getStop()); - assertSame(type1, bar.getType()); - assertEquals("label1", bar.getLabel()); + assertThat(bar.getStart()).isEqualTo(2); + assertThat(bar.getStop()).isEqualTo(3); + assertThat(bar.getType()).isSameAs(type1); + assertThat(bar.getLabel()).isEqualTo("label1"); } @Test @@ -167,19 +160,19 @@ public class ProfilerChartTest extends FoundationTestCase { ChartRow row2 = new ChartRow("2", 1); ChartRow row3 = new ChartRow("3", 1); - assertEquals("1", row1.getId()); - assertEquals(0, row1.getIndex()); + assertThat(row1.getId()).isEqualTo("1"); + assertThat(row1.getIndex()).isEqualTo(0); - assertEquals(-1, row1.compareTo(row2)); - assertEquals(1, row2.compareTo(row1)); - assertEquals(0, row2.compareTo(row3)); + assertThat(row1.compareTo(row2)).isEqualTo(-1); + assertThat(row2.compareTo(row1)).isEqualTo(1); + assertThat(row2.compareTo(row3)).isEqualTo(0); row1.addBar(new ChartBar(row1, 1, 2, new ChartBarType("name1", Color.BLACK), false, "label1")); row1.addBar(new ChartBar(row1, 2, 3, new ChartBarType("name2", Color.RED), false, "label2")); assertThat(row1.getBars()).hasSize(2); - assertEquals("label1", row1.getBars().get(0).getLabel()); - assertEquals("label2", row1.getBars().get(1).getLabel()); + assertThat(row1.getBars().get(0).getLabel()).isEqualTo("label1"); + assertThat(row1.getBars().get(1).getLabel()).isEqualTo("label2"); } @Test @@ -188,17 +181,17 @@ public class ProfilerChartTest extends FoundationTestCase { ChartBarType type2 = new ChartBarType("name2", Color.RED); ChartBarType type3 = new ChartBarType("name2", Color.GREEN); - assertEquals(-1, type1.compareTo(type2)); - assertEquals(1, type2.compareTo(type1)); - assertEquals(0, type2.compareTo(type3)); + assertThat(type1.compareTo(type2)).isEqualTo(-1); + assertThat(type2.compareTo(type1)).isEqualTo(1); + assertThat(type2.compareTo(type3)).isEqualTo(0); - assertEquals(type3, type2); - assertFalse(type1.equals(type3)); - assertFalse(type1.equals(type2)); + assertThat(type2).isEqualTo(type3); + assertThat(type1.equals(type3)).isFalse(); + assertThat(type1.equals(type2)).isFalse(); - assertEquals(type3.hashCode(), type2.hashCode()); - assertFalse(type1.hashCode() == type2.hashCode()); - assertFalse(type1.hashCode() == type3.hashCode()); + assertThat(type2.hashCode()).isEqualTo(type3.hashCode()); + assertThat(type1.hashCode() == type2.hashCode()).isFalse(); + assertThat(type1.hashCode() == type3.hashCode()).isFalse(); } @Test @@ -206,11 +199,11 @@ public class ProfilerChartTest extends FoundationTestCase { ChartRow row1 = new ChartRow("1", 0); ChartBarType type = new ChartBarType("name1", Color.BLACK); ChartBar bar1 = new ChartBar(row1, 1, 2, type, false, "label1"); - assertEquals(row1, bar1.getRow()); - assertEquals(1, bar1.getStart()); - assertEquals(2, bar1.getStop()); - assertSame(type, bar1.getType()); - assertEquals("label1", bar1.getLabel()); + assertThat(bar1.getRow()).isEqualTo(row1); + assertThat(bar1.getStart()).isEqualTo(1); + assertThat(bar1.getStop()).isEqualTo(2); + assertThat(bar1.getType()).isSameAs(type); + assertThat(bar1.getLabel()).isEqualTo("label1"); } @Test @@ -228,12 +221,12 @@ public class ProfilerChartTest extends FoundationTestCase { TestingChartVisitor visitor = new TestingChartVisitor(); chart.accept(visitor); - assertEquals(1, visitor.beginChartCount); - assertEquals(1, visitor.endChartCount); - assertEquals(3, visitor.rowCount); - assertEquals(6, visitor.barCount); - assertEquals(0, visitor.columnCount); - assertEquals(0, visitor.lineCount); + assertThat(visitor.beginChartCount).isEqualTo(1); + assertThat(visitor.endChartCount).isEqualTo(1); + assertThat(visitor.rowCount).isEqualTo(3); + assertThat(visitor.barCount).isEqualTo(6); + assertThat(visitor.columnCount).isEqualTo(0); + assertThat(visitor.lineCount).isEqualTo(0); } private ProfileInfo createProfileInfo(Runnable runnable, int noOfRows) throws Exception { diff --git a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java index e6175a890c..0666d1f156 100644 --- a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java +++ b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerTest.java @@ -15,9 +15,6 @@ package com.google.devtools.build.lib.profiler; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.devtools.build.lib.profiler.Profiler.ProfiledTaskKinds; @@ -59,13 +56,13 @@ public class ProfilerTest extends FoundationTestCase { @Test public void testProfilerActivation() throws Exception { Path cacheFile = cacheDir.getRelative("profile1.dat"); - assertFalse(profiler.isActive()); + assertThat(profiler.isActive()).isFalse(); profiler.start(ProfiledTaskKinds.ALL, cacheFile.getOutputStream(), "basic test", false, BlazeClock.instance(), BlazeClock.instance().nanoTime()); - assertTrue(profiler.isActive()); + assertThat(profiler.isActive()).isTrue(); profiler.stop(); - assertFalse(profiler.isActive()); + assertThat(profiler.isActive()).isFalse(); } @Test @@ -81,14 +78,14 @@ public class ProfilerTest extends FoundationTestCase { info.calculateStats(); ProfileInfo.Task task = info.allTasksById.get(0); - assertEquals(1, task.id); - assertEquals(ProfilerTask.ACTION, task.type); - assertEquals("action task", task.getDescription()); + assertThat(task.id).isEqualTo(1); + assertThat(task.type).isEqualTo(ProfilerTask.ACTION); + assertThat(task.getDescription()).isEqualTo("action task"); task = info.allTasksById.get(1); - assertEquals(2, task.id); - assertEquals(ProfilerTask.TEST, task.type); - assertEquals("event", task.getDescription()); + assertThat(task.id).isEqualTo(2); + assertThat(task.type).isEqualTo(ProfilerTask.TEST); + assertThat(task.getDescription()).isEqualTo("event"); } @Test @@ -122,7 +119,7 @@ public class ProfilerTest extends FoundationTestCase { assertThat(info.allTasksById).hasSize(6); // only 5 tasks + finalization should be recorded ProfileInfo.Task task = info.allTasksById.get(0); - assertTrue(task.stats.isEmpty()); + assertThat(task.stats.isEmpty()).isTrue(); task = info.allTasksById.get(1); int count = 0; @@ -131,21 +128,21 @@ public class ProfilerTest extends FoundationTestCase { count++; } } - assertEquals(2, count); // only children are GENERIC and ACTION_CHECK - assertEquals(task.aggregatedStats.toArray().length, ProfilerTask.TASK_COUNT); - assertEquals(2, task.aggregatedStats.getAttr(ProfilerTask.VFS_STAT).count); + assertThat(count).isEqualTo(2); // only children are GENERIC and ACTION_CHECK + assertThat(ProfilerTask.TASK_COUNT).isEqualTo(task.aggregatedStats.toArray().length); + assertThat(task.aggregatedStats.getAttr(ProfilerTask.VFS_STAT).count).isEqualTo(2); task = info.allTasksById.get(2); assertThat(task.durationNanos).isEqualTo(0); task = info.allTasksById.get(3); - assertEquals(2, task.stats.getAttr(ProfilerTask.VFS_STAT).count); - assertEquals(1, task.subtasks.length); - assertEquals("stat2", task.subtasks[0].getDescription()); + assertThat(task.stats.getAttr(ProfilerTask.VFS_STAT).count).isEqualTo(2); + assertThat(task.subtasks).hasLength(1); + assertThat(task.subtasks[0].getDescription()).isEqualTo("stat2"); // assert that startTime grows with id long time = -1; for (ProfileInfo.Task t : info.allTasksById) { - assertTrue(t.startTime >= time); + assertThat(t.startTime).isAtLeast(time); time = t.startTime; } } @@ -165,7 +162,7 @@ public class ProfilerTest extends FoundationTestCase { assertThat(info.allTasksById).hasSize(3); // 2 tasks + finalization should be recorded ProfileInfo.Task task = info.allTasksById.get(1); - assertEquals(ProfilerTask.VFS_STAT, task.type); + assertThat(task.type).isEqualTo(ProfilerTask.VFS_STAT); // Check that task would have been dropped if profiler was not configured to record everything. assertThat(task.durationNanos).isLessThan(ProfilerTask.VFS_STAT.minDuration); @@ -180,8 +177,8 @@ public class ProfilerTest extends FoundationTestCase { profiler.logSimpleTask(10000, 20000, ProfilerTask.VFS_STAT, "stat"); profiler.logSimpleTask(20000, 30000, ProfilerTask.REMOTE_EXECUTION, "remote execution"); - assertTrue(profiler.isProfiling(ProfilerTask.VFS_STAT)); - assertFalse(profiler.isProfiling(ProfilerTask.REMOTE_EXECUTION)); + assertThat(profiler.isProfiling(ProfilerTask.VFS_STAT)).isTrue(); + assertThat(profiler.isProfiling(ProfilerTask.REMOTE_EXECUTION)).isFalse(); profiler.stop(); @@ -190,7 +187,7 @@ public class ProfilerTest extends FoundationTestCase { assertThat(info.allTasksById).hasSize(1); // only VFS_STAT task should be recorded ProfileInfo.Task task = info.allTasksById.get(0); - assertEquals(ProfilerTask.VFS_STAT, task.type); + assertThat(task.type).isEqualTo(ProfilerTask.VFS_STAT); } @Test @@ -201,8 +198,8 @@ public class ProfilerTest extends FoundationTestCase { BlazeClock.instance(), BlazeClock.instance().nanoTime()); profiler.logSimpleTask(10000, 20000, ProfilerTask.VFS_STAT, "stat"); - assertTrue(ProfilerTask.VFS_STAT.collectsSlowestInstances()); - assertFalse(profiler.isProfiling(ProfilerTask.VFS_STAT)); + assertThat(ProfilerTask.VFS_STAT.collectsSlowestInstances()).isTrue(); + assertThat(profiler.isProfiling(ProfilerTask.VFS_STAT)).isFalse(); profiler.stop(); @@ -264,23 +261,23 @@ public class ProfilerTest extends FoundationTestCase { ProfileInfo info = ProfileInfo.loadProfile(cacheFile); info.calculateStats(); info.analyzeRelationships(); - assertEquals(4 + 10000 + 10000, info.allTasksById.size()); // total number of tasks - assertEquals(3, info.tasksByThread.size()); // total number of threads + assertThat(info.allTasksById).hasSize(4 + 10000 + 10000); // total number of tasks + assertThat(info.tasksByThread).hasSize(3); // total number of threads // while main thread had 3 tasks, 2 of them were nested, so tasksByThread // would contain only one "main task" task - assertEquals(2, info.tasksByThread.get(id).length); + assertThat(info.tasksByThread.get(id)).hasLength(2); ProfileInfo.Task mainTask = info.tasksByThread.get(id)[0]; - assertEquals("main task", mainTask.getDescription()); - assertEquals(2, mainTask.subtasks.length); + assertThat(mainTask.getDescription()).isEqualTo("main task"); + assertThat(mainTask.subtasks).hasLength(2); // other threads had 10000 independent recorded tasks each - assertEquals(10000, info.tasksByThread.get(id1).length); - assertEquals(10000, info.tasksByThread.get(id2).length); + assertThat(info.tasksByThread.get(id1)).hasLength(10000); + assertThat(info.tasksByThread.get(id2)).hasLength(10000); int startId = mainTask.subtasks[0].id; // id of "starting threads" int endId = mainTask.subtasks[1].id; // id of "joining" - assertTrue(startId < info.tasksByThread.get(id1)[0].id); - assertTrue(startId < info.tasksByThread.get(id2)[0].id); - assertTrue(endId > info.tasksByThread.get(id1)[9999].id); - assertTrue(endId > info.tasksByThread.get(id2)[9999].id); + assertThat(startId).isLessThan(info.tasksByThread.get(id1)[0].id); + assertThat(startId).isLessThan(info.tasksByThread.get(id2)[0].id); + assertThat(endId).isGreaterThan(info.tasksByThread.get(id1)[9999].id); + assertThat(endId).isGreaterThan(info.tasksByThread.get(id2)[9999].id); } @Test @@ -355,19 +352,19 @@ public class ProfilerTest extends FoundationTestCase { ProfileInfo info = ProfileInfo.loadProfile(cacheFile); info.calculateStats(); - assertFalse(info.isCorruptedOrIncomplete()); + assertThat(info.isCorruptedOrIncomplete()).isFalse(); Path corruptedFile = cacheDir.getRelative("profile5bad.dat"); FileSystemUtils.writeContent( corruptedFile, Arrays.copyOf(FileSystemUtils.readContent(cacheFile), 2000)); info = ProfileInfo.loadProfile(corruptedFile); info.calculateStats(); - assertTrue(info.isCorruptedOrIncomplete()); + assertThat(info.isCorruptedOrIncomplete()).isTrue(); // Since root tasks will appear after nested tasks in the profile file and // we have exactly one nested task for each root task, then following will be // always true for our corrupted file: // 0 <= number_of_all_tasks - 2*number_of_root_tasks <= 1 - assertEquals(info.rootTasksById.size(), info.allTasksById.size() / 2); + assertThat(info.allTasksById.size() / 2).isEqualTo(info.rootTasksById.size()); } @Test @@ -386,19 +383,19 @@ public class ProfilerTest extends FoundationTestCase { // Validate our test profile. ProfileInfo info = ProfileInfo.loadProfile(dataFile); info.calculateStats(); - assertFalse(info.isCorruptedOrIncomplete()); - assertEquals(2, info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count); - assertEquals(0, info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count); + assertThat(info.isCorruptedOrIncomplete()).isFalse(); + assertThat(info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count).isEqualTo(2); + assertThat(info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count).isEqualTo(0); // Now replace "TEST" type with something unsupported - e.g. "XXXX". InputStream in = new InflaterInputStream(dataFile.getInputStream(), new Inflater(false), 65536); byte[] buffer = new byte[60000]; int len = in.read(buffer); in.close(); - assertTrue(len < buffer.length); // Validate that file was completely decoded. + assertThat(len).isLessThan(buffer.length); // Validate that file was completely decoded. String content = new String(buffer, ISO_8859_1); int infoIndex = content.indexOf("TEST"); - assertTrue(infoIndex > 0); + assertThat(infoIndex).isGreaterThan(0); content = content.substring(0, infoIndex) + "XXXX" + content.substring(infoIndex + 4); OutputStream out = new DeflaterOutputStream(dataFile.getOutputStream(), new Deflater(Deflater.BEST_SPEED, false), 65536); @@ -408,11 +405,11 @@ public class ProfilerTest extends FoundationTestCase { // Validate that XXXX records were classified as UNKNOWN. info = ProfileInfo.loadProfile(dataFile); info.calculateStats(); - assertFalse(info.isCorruptedOrIncomplete()); - assertEquals(0, info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count); - assertEquals(1, info.getStatsForType(ProfilerTask.SCANNER, info.rootTasksById).count); - assertEquals(1, info.getStatsForType(ProfilerTask.EXCEPTION, info.rootTasksById).count); - assertEquals(2, info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count); + assertThat(info.isCorruptedOrIncomplete()).isFalse(); + assertThat(info.getStatsForType(ProfilerTask.TEST, info.rootTasksById).count).isEqualTo(0); + assertThat(info.getStatsForType(ProfilerTask.SCANNER, info.rootTasksById).count).isEqualTo(1); + assertThat(info.getStatsForType(ProfilerTask.EXCEPTION, info.rootTasksById).count).isEqualTo(1); + assertThat(info.getStatsForType(ProfilerTask.UNKNOWN, info.rootTasksById).count).isEqualTo(2); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java index 08a0bb1928..b9b9862b31 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java @@ -255,7 +255,8 @@ public class ProtoCompileActionBuilderTest { ImmutableList.<String>of() /* protocOpts */); fail("Expected an exception"); } catch (IllegalStateException e) { - assertThat(e.getMessage()) + assertThat(e) + .hasMessageThat() .isEqualTo( "Invocation name pluginName appears more than once. " + "This could lead to incorrect proto-compiler behavior"); |