diff options
author | 2017-05-30 12:35:33 +0200 | |
---|---|---|
committer | 2017-05-30 12:51:57 +0200 | |
commit | aea56b36af994b269800602e36000c293cabd00b (patch) | |
tree | 794f6b3b2528353cc39bd383730d408d4ff25233 /src/test/java/com/google/devtools/build/lib/skyframe | |
parent | 229f393bf460700594ae032a551879e026bd0b91 (diff) |
Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
30 files changed, 571 insertions, 607 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java index 36d2559b23..68437dbdb3 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java @@ -15,9 +15,6 @@ package com.google.devtools.build.lib.skyframe; 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.assertTrue; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; @@ -81,8 +78,8 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter); - assertFalse(result.hasError()); - assertFalse(result.get(skyKey).getPackage().containsErrors()); + assertThat(result.hasError()).isFalse(); + assertThat(result.get(skyKey).getPackage().containsErrors()).isFalse(); } @Test @@ -98,12 +95,12 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); Throwable e = errorInfo.getException(); - assertEquals(skyKey, errorInfo.getRootCauseOfException()); + assertThat(errorInfo.getRootCauseOfException()).isEqualTo(skyKey); assertThat(e).isInstanceOf(NoSuchPackageException.class); - assertThat(e.getMessage()).contains("bork"); + assertThat(e).hasMessageThat().contains("bork"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionDataTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionDataTest.java index 7ef96779fd..68f423aa17 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionDataTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionDataTest.java @@ -13,7 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertSame; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -83,13 +83,13 @@ public class ActionDataTest extends TimestampBuilderTestCase { .buildArtifacts( reporter, outputs, null, null, null, null, executor, null, /*explain=*/ false, null, null); - assertSame(executor, action.executor); + assertThat(action.executor).isSameAs(executor); executor = new DummyExecutor(scratch.dir("/")); amnesiacBuilder() .buildArtifacts( reporter, outputs, null, null, null, null, executor, null, /*explain=*/ false, null, null); - assertSame(executor, action.executor); + assertThat(action.executor).isSameAs(executor); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java index e6e912d7a2..ee6f419940 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java @@ -15,18 +15,15 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static org.junit.Assert.assertEquals; import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog.InactivityMonitor; import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog.InactivityReporter; - +import java.util.ArrayList; +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.ArrayList; -import java.util.List; - /** Tests for ActionExecutionInactivityWatchdog. */ @RunWith(JUnit4.class) public class ActionExecutionInactivityWatchdogTest { @@ -144,7 +141,7 @@ public class ActionExecutionInactivityWatchdogTest { watchdog.stop(); } - assertEquals(shouldReport, didReportInactivity[0]); + assertThat(didReportInactivity[0]).isEqualTo(shouldReport); assertThat(sleepsAndWaits) .containsExactly( "wait:5", 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 21afd0a256..26d7565320 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,11 +15,7 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.skyframe.FileArtifactValue.create; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import com.google.common.base.Predicate; @@ -201,7 +197,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { create(createDerivedArtifact("no-read")); fail(); } catch (IOException e) { - assertSame(exception, e); + assertThat(e).isSameAs(exception); } } @@ -226,7 +222,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { evaluateArtifactValue(createSourceArtifact("bad")); fail(); } catch (MissingInputFileException e) { - assertThat(e.getMessage()).contains(exception.getMessage()); + assertThat(e).hasMessageThat().contains(exception.getMessage()); } } @@ -236,7 +232,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { Path path = artifact.getPath(); writeFile(path, "hello"); //Non-empty file. FileArtifactValue value = create(artifact); - assertArrayEquals(path.getMD5Digest(), value.getDigest()); + assertThat(value.getDigest()).isEqualTo(path.getMD5Digest()); try { value.getModifiedTime(); fail("mtime for non-empty file should not be stored."); @@ -252,8 +248,8 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { FileSystemUtils.createDirectoryAndParents(path); path.setLastModifiedTime(1L); FileArtifactValue value = create(artifact); - assertNull(value.getDigest()); - assertEquals(1L, value.getModifiedTime()); + assertThat(value.getDigest()).isNull(); + assertThat(value.getModifiedTime()).isEqualTo(1L); } // Empty files are the same as normal files -- mtime is not stored. @@ -264,8 +260,8 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { writeFile(path, ""); path.setLastModifiedTime(1L); FileArtifactValue value = create(artifact); - assertArrayEquals(path.getMD5Digest(), value.getDigest()); - assertEquals(0L, value.getSize()); + assertThat(value.getDigest()).isEqualTo(path.getMD5Digest()); + assertThat(value.getSize()).isEqualTo(0L); } @Test @@ -326,10 +322,10 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { TreeFileArtifact treeFileArtifact2 = createFakeTreeFileArtifact(artifact, "child2", "hello2"); TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact); - assertNotNull(value.getChildValues().get(treeFileArtifact1)); - assertNotNull(value.getChildValues().get(treeFileArtifact2)); - assertNotNull(value.getChildValues().get(treeFileArtifact1).getDigest()); - assertNotNull(value.getChildValues().get(treeFileArtifact2).getDigest()); + assertThat(value.getChildValues().get(treeFileArtifact1)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); } @Test @@ -349,10 +345,10 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2)); TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact2); - assertNotNull(value.getChildValues().get(treeFileArtifact1)); - assertNotNull(value.getChildValues().get(treeFileArtifact2)); - assertNotNull(value.getChildValues().get(treeFileArtifact1).getDigest()); - assertNotNull(value.getChildValues().get(treeFileArtifact2).getDigest()); + assertThat(value.getChildValues().get(treeFileArtifact1)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); } @Test @@ -377,10 +373,10 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { ActionsTestUtil.createDummySpawnActionTemplate(artifact2, artifact3)); TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact3); - assertNotNull(value.getChildValues().get(treeFileArtifact1)); - assertNotNull(value.getChildValues().get(treeFileArtifact2)); - assertNotNull(value.getChildValues().get(treeFileArtifact1).getDigest()); - assertNotNull(value.getChildValues().get(treeFileArtifact2).getDigest()); + assertThat(value.getChildValues().get(treeFileArtifact1)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2)).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); + assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); } private void file(Path path, String contents) throws Exception { @@ -438,12 +434,12 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { private void assertValueMatches(FileStatus file, byte[] digest, FileArtifactValue value) throws IOException { - assertEquals(file.getSize(), value.getSize()); + assertThat(value.getSize()).isEqualTo(file.getSize()); if (digest == null) { - assertNull(value.getDigest()); - assertEquals(file.getLastModifiedTime(), value.getModifiedTime()); + assertThat(value.getDigest()).isNull(); + assertThat(value.getModifiedTime()).isEqualTo(file.getLastModifiedTime()); } else { - assertArrayEquals(digest, value.getDigest()); + assertThat(value.getDigest()).isEqualTo(digest); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java index 9612febb38..9ee1f9dc36 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java @@ -330,7 +330,7 @@ public class ConfigurationsForTargetsWithDynamicConfigurationsTest applier.split(newSplitTransition("disallowed second split")); fail("expected failure: deps cannot apply more than one split transition each"); } catch (IllegalStateException e) { - assertThat(e.getMessage()).contains("dependency edges may apply at most one split"); + assertThat(e).hasMessageThat().contains("dependency edges may apply at most one split"); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java index 1260439a7d..d65779f372 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -111,25 +109,26 @@ public class ContainingPackageLookupFunctionTest extends FoundationTestCase { @Test public void testNoContainingPackage() throws Exception { ContainingPackageLookupValue value = lookupContainingPackage("a/b"); - assertFalse(value.hasContainingPackage()); + assertThat(value.hasContainingPackage()).isFalse(); } @Test public void testContainingPackageIsParent() throws Exception { scratch.file("a/BUILD"); ContainingPackageLookupValue value = lookupContainingPackage("a/b"); - assertTrue(value.hasContainingPackage()); - assertEquals(PackageIdentifier.createInMainRepo("a"), value.getContainingPackageName()); - assertEquals(rootDirectory, value.getContainingPackageRoot()); + assertThat(value.hasContainingPackage()).isTrue(); + assertThat(value.getContainingPackageName()).isEqualTo(PackageIdentifier.createInMainRepo("a")); + assertThat(value.getContainingPackageRoot()).isEqualTo(rootDirectory); } @Test public void testContainingPackageIsSelf() throws Exception { scratch.file("a/b/BUILD"); ContainingPackageLookupValue value = lookupContainingPackage("a/b"); - assertTrue(value.hasContainingPackage()); - assertEquals(PackageIdentifier.createInMainRepo("a/b"), value.getContainingPackageName()); - assertEquals(rootDirectory, value.getContainingPackageRoot()); + assertThat(value.hasContainingPackage()).isTrue(); + assertThat(value.getContainingPackageName()) + .isEqualTo(PackageIdentifier.createInMainRepo("a/b")); + assertThat(value.getContainingPackageRoot()).isEqualTo(rootDirectory); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java index 2a6f85eb05..16873d3f2a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java @@ -14,9 +14,7 @@ package com.google.devtools.build.lib.skyframe; 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.assertTrue; +import static com.google.common.truth.Truth.assertWithMessage; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; @@ -64,11 +62,12 @@ public class DiffAwarenessManagerTest { Path pathEntry = root.getRelative("pathEntry"); DiffAwarenessFactoryStub factory = new DiffAwarenessFactoryStub(); DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory)); - assertEquals( - "Expected EVERYTHING_MODIFIED since there are no factories", - ModifiedFileSet.EVERYTHING_MODIFIED, - manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY) - .getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED since there are no factories") + .that( + manager + .getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY) + .getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); events.assertNoWarningsOrErrors(); } @@ -82,12 +81,18 @@ public class DiffAwarenessManagerTest { factory.inject(pathEntry, diffAwareness1); DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory)); manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertFalse("diffAwareness1 shouldn't have been closed yet", diffAwareness1.closed()); + assertWithMessage("diffAwareness1 shouldn't have been closed yet") + .that(diffAwareness1.closed()) + .isFalse(); manager.reset(); - assertTrue("diffAwareness1 should have been closed by reset", diffAwareness1.closed()); + assertWithMessage("diffAwareness1 should have been closed by reset") + .that(diffAwareness1.closed()) + .isTrue(); factory.inject(pathEntry, diffAwareness2); manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertFalse("diffAwareness2 shouldn't have been closed yet", diffAwareness2.closed()); + assertWithMessage("diffAwareness2 shouldn't have been closed yet") + .that(diffAwareness2.closed()) + .isFalse(); events.assertNoWarningsOrErrors(); } @@ -104,25 +109,26 @@ public class DiffAwarenessManagerTest { DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory)); ProcessableModifiedFileSet firstProcessableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals( - "Expected EVERYTHING_MODIFIED on first call to getDiff", - ModifiedFileSet.EVERYTHING_MODIFIED, - firstProcessableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED on first call to getDiff") + .that(firstProcessableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); firstProcessableDiff.markProcessed(); ProcessableModifiedFileSet processableDiff1 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(diff1, processableDiff1.getModifiedFileSet()); + assertThat(processableDiff1.getModifiedFileSet()).isEqualTo(diff1); ProcessableModifiedFileSet processableDiff2 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(ModifiedFileSet.union(diff1, diff2), processableDiff2.getModifiedFileSet()); + assertThat(processableDiff2.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.union(diff1, diff2)); processableDiff2.markProcessed(); ProcessableModifiedFileSet processableDiff3 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(diff3, processableDiff3.getModifiedFileSet()); + assertThat(processableDiff3.getModifiedFileSet()).isEqualTo(diff3); events.assertNoWarningsOrErrors(); ProcessableModifiedFileSet processableDiff4 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(ModifiedFileSet.EVERYTHING_MODIFIED, processableDiff4.getModifiedFileSet()); + assertThat(processableDiff4.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); events.assertContainsWarning("error"); } @@ -148,50 +154,45 @@ public class DiffAwarenessManagerTest { ProcessableModifiedFileSet processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); events.assertNoWarningsOrErrors(); - assertEquals( - "Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness1", - ModifiedFileSet.EVERYTHING_MODIFIED, - processableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness1") + .that(processableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); processableDiff.markProcessed(); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); events.assertContainsEventWithFrequency("error in getCurrentView", 1); - assertEquals( - "Expected EVERYTHING_MODIFIED because of broken getCurrentView", - ModifiedFileSet.EVERYTHING_MODIFIED, - processableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED because of broken getCurrentView") + .that(processableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); processableDiff.markProcessed(); factory1.remove(pathEntry); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals( - "Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness2", - ModifiedFileSet.EVERYTHING_MODIFIED, - processableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness2") + .that(processableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); processableDiff.markProcessed(); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(diff2, processableDiff.getModifiedFileSet()); + assertThat(processableDiff.getModifiedFileSet()).isEqualTo(diff2); processableDiff.markProcessed(); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); events.assertContainsEventWithFrequency("error in getDiff", 1); - assertEquals( - "Expected EVERYTHING_MODIFIED because of broken getDiff", - ModifiedFileSet.EVERYTHING_MODIFIED, - processableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED because of broken getDiff") + .that(processableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); processableDiff.markProcessed(); factory2.remove(pathEntry); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals( - "Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness3", - ModifiedFileSet.EVERYTHING_MODIFIED, - processableDiff.getModifiedFileSet()); + assertWithMessage("Expected EVERYTHING_MODIFIED on first call to getDiff for diffAwareness3") + .that(processableDiff.getModifiedFileSet()) + .isEqualTo(ModifiedFileSet.EVERYTHING_MODIFIED); processableDiff.markProcessed(); processableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY); - assertEquals(diff3, processableDiff.getModifiedFileSet()); + assertThat(processableDiff.getModifiedFileSet()).isEqualTo(diff3); processableDiff.markProcessed(); } 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 8be17f2064..43d0353a1a 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 @@ -14,14 +14,9 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static com.google.devtools.build.lib.skyframe.SkyframeExecutor.DEFAULT_THREAD_COUNT; import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Function; @@ -187,7 +182,7 @@ public class FileFunctionTest { EvaluationResult<FileValue> result = driver.evaluate( ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); return result.get(key); } @@ -207,26 +202,26 @@ public class FileFunctionTest { @Test public void testIsDirectory() throws Exception { - assertFalse(valueForPath(file("a")).isDirectory()); - assertFalse(valueForPath(path("nonexistent")).isDirectory()); - assertTrue(valueForPath(directory("dir")).isDirectory()); + assertThat(valueForPath(file("a")).isDirectory()).isFalse(); + assertThat(valueForPath(path("nonexistent")).isDirectory()).isFalse(); + assertThat(valueForPath(directory("dir")).isDirectory()).isTrue(); - assertFalse(valueForPath(symlink("sa", "a")).isDirectory()); - assertFalse(valueForPath(symlink("smissing", "missing")).isDirectory()); - assertTrue(valueForPath(symlink("sdir", "dir")).isDirectory()); - assertTrue(valueForPath(symlink("ssdir", "sdir")).isDirectory()); + assertThat(valueForPath(symlink("sa", "a")).isDirectory()).isFalse(); + assertThat(valueForPath(symlink("smissing", "missing")).isDirectory()).isFalse(); + assertThat(valueForPath(symlink("sdir", "dir")).isDirectory()).isTrue(); + assertThat(valueForPath(symlink("ssdir", "sdir")).isDirectory()).isTrue(); } @Test public void testIsFile() throws Exception { - assertTrue(valueForPath(file("a")).isFile()); - assertFalse(valueForPath(path("nonexistent")).isFile()); - assertFalse(valueForPath(directory("dir")).isFile()); + assertThat(valueForPath(file("a")).isFile()).isTrue(); + assertThat(valueForPath(path("nonexistent")).isFile()).isFalse(); + assertThat(valueForPath(directory("dir")).isFile()).isFalse(); - assertTrue(valueForPath(symlink("sa", "a")).isFile()); - assertFalse(valueForPath(symlink("smissing", "missing")).isFile()); - assertFalse(valueForPath(symlink("sdir", "dir")).isFile()); - assertTrue(valueForPath(symlink("ssfile", "sa")).isFile()); + assertThat(valueForPath(symlink("sa", "a")).isFile()).isTrue(); + assertThat(valueForPath(symlink("smissing", "missing")).isFile()).isFalse(); + assertThat(valueForPath(symlink("sdir", "dir")).isFile()).isFalse(); + assertThat(valueForPath(symlink("ssfile", "sa")).isFile()).isTrue(); } @Test @@ -428,7 +423,7 @@ public class FileFunctionTest { FileValue a = valueForPath(path("file")); Path p = file("file"); FileValue b = valueForPath(p); - assertFalse(a.equals(b)); + assertThat(a.equals(b)).isFalse(); } @Test @@ -447,7 +442,7 @@ public class FileFunctionTest { p.setLastModifiedTime(1L); assertThat(valueForPath(p)).isNotEqualTo(a); p.setLastModifiedTime(0L); - assertEquals(a, valueForPath(p)); + assertThat(valueForPath(p)).isEqualTo(a); FileSystemUtils.writeContentAsLatin1(p, "content"); // Same digest, but now non-empty. assertThat(valueForPath(p)).isNotEqualTo(a); @@ -460,7 +455,7 @@ public class FileFunctionTest { p.setLastModifiedTime(0L); FileValue value = valueForPath(p); - assertTrue(value.exists()); + assertThat(value.exists()).isTrue(); assertThat(value.getDigest()).isNull(); p.setLastModifiedTime(10L); @@ -498,7 +493,7 @@ public class FileFunctionTest { FileValue a = valueForPath(p); p.setLastModifiedTime(42); FileValue b = valueForPath(p); - assertFalse(a.equals(b)); + assertThat(a.equals(b)).isFalse(); } @Test @@ -508,7 +503,7 @@ public class FileFunctionTest { FileValue a = valueForPath(p); FileSystemUtils.writeContentAsLatin1(p, "goop"); FileValue b = valueForPath(p); - assertFalse(a.equals(b)); + assertThat(a.equals(b)).isFalse(); } @Test @@ -529,7 +524,7 @@ public class FileFunctionTest { FileValue a = valueForPath(p); p.delete(); FileValue b = valueForPath(p); - assertFalse(a.equals(b)); + assertThat(a.equals(b)).isFalse(); } @Test @@ -542,9 +537,9 @@ public class FileFunctionTest { p.delete(); FileSystemUtils.createDirectoryAndParents(pkgRoot.getRelative("file")); FileValue c = valueForPath(p); - assertFalse(a.equals(b)); - assertFalse(b.equals(c)); - assertFalse(a.equals(c)); + assertThat(a.equals(b)).isFalse(); + assertThat(b.equals(c)).isFalse(); + assertThat(a.equals(c)).isFalse(); } @Test @@ -646,7 +641,7 @@ public class FileFunctionTest { fail(String.format("Evaluation error for %s: %s", key, result.getError())); } FileValue oldValue = (FileValue) result.get(key); - assertTrue(oldValue.exists()); + assertThat(oldValue.exists()).isTrue(); file.delete(); differencer.invalidate(ImmutableList.of(fileStateSkyKey("/outsideroot"))); @@ -657,8 +652,8 @@ public class FileFunctionTest { fail(String.format("Evaluation error for %s: %s", key, result.getError())); } FileValue newValue = (FileValue) result.get(key); - assertNotSame(oldValue, newValue); - assertFalse(newValue.exists()); + assertThat(newValue).isNotSameAs(oldValue); + assertThat(newValue.exists()).isFalse(); } @Test @@ -675,7 +670,7 @@ public class FileFunctionTest { assertThatEvaluationResult(result).hasNoError(); FileValue value = (FileValue) result.get(key); assertThat(value).isNotNull(); - assertFalse(value.exists()); + assertThat(value.exists()).isFalse(); } @Test @@ -694,7 +689,7 @@ public class FileFunctionTest { assertThatEvaluationResult(result).hasNoError(); FileValue value = (FileValue) result.get(key); assertThat(value).isNotNull(); - assertFalse(value.exists()); + assertThat(value.exists()).isFalse(); } @Test @@ -713,7 +708,7 @@ public class FileFunctionTest { assertThatEvaluationResult(result).hasNoError(); FileValue value = (FileValue) result.get(key); assertThat(value).isNotNull(); - assertFalse(value.exists()); + assertThat(value.exists()).isFalse(); } @Test @@ -731,7 +726,7 @@ public class FileFunctionTest { assertThatEvaluationResult(result).hasNoError(); FileValue value = (FileValue) result.get(key); assertThat(value).isNotNull(); - assertFalse(value.exists()); + assertThat(value.exists()).isFalse(); } @Test @@ -749,7 +744,7 @@ public class FileFunctionTest { assertThatEvaluationResult(result).hasNoError(); FileValue value = (FileValue) result.get(key); assertThat(value).isNotNull(); - assertTrue(value.exists()); + assertThat(value.exists()).isTrue(); assertThat(value.realRootedPath().getRelativePath().getPathString()).isEqualTo("insideroot"); } @@ -775,7 +770,7 @@ public class FileFunctionTest { Path file = file("file"); int fileSize = 20; FileSystemUtils.writeContentAsLatin1(file, Strings.repeat("a", fileSize)); - assertEquals(fileSize, valueForPath(file).getSize()); + assertThat(valueForPath(file).getSize()).isEqualTo(fileSize); Path dir = directory("directory"); file(dir.getChild("child").getPathString()); try { @@ -793,8 +788,8 @@ public class FileFunctionTest { } Path symlink = symlink("link", "/root/file"); // Symlink stores size of target, not link. - assertEquals(fileSize, valueForPath(symlink).getSize()); - assertTrue(symlink.delete()); + assertThat(valueForPath(symlink).getSize()).isEqualTo(fileSize); + assertThat(symlink.delete()).isTrue(); symlink = symlink("link", "/root/directory"); try { valueForPath(symlink).getSize(); @@ -802,7 +797,7 @@ public class FileFunctionTest { } catch (IllegalStateException e) { // Expected. } - assertTrue(symlink.delete()); + assertThat(symlink.delete()).isTrue(); symlink = symlink("link", "/root/noexist"); try { valueForPath(symlink).getSize(); @@ -829,54 +824,54 @@ public class FileFunctionTest { FileSystemUtils.writeContentAsLatin1(file, Strings.repeat("a", 20)); byte[] digest = file.getMD5Digest(); expectedCalls++; - assertEquals(expectedCalls, digestCalls.get()); + assertThat(digestCalls.get()).isEqualTo(expectedCalls); FileValue value = valueForPath(file); expectedCalls++; - assertEquals(expectedCalls, digestCalls.get()); - assertArrayEquals(digest, value.getDigest()); + assertThat(digestCalls.get()).isEqualTo(expectedCalls); + assertThat(value.getDigest()).isEqualTo(digest); // Digest is cached -- no filesystem access. - assertEquals(expectedCalls, digestCalls.get()); + assertThat(digestCalls.get()).isEqualTo(expectedCalls); fastDigest = false; digestCalls.set(0); value = valueForPath(file); // No new digest calls. - assertEquals(0, digestCalls.get()); - assertNull(value.getDigest()); - assertEquals(0, digestCalls.get()); + assertThat(digestCalls.get()).isEqualTo(0); + assertThat(value.getDigest()).isNull(); + assertThat(digestCalls.get()).isEqualTo(0); fastDigest = true; Path dir = directory("directory"); try { - assertNull(valueForPath(dir).getDigest()); + assertThat(valueForPath(dir).getDigest()).isNull(); fail(); } catch (IllegalStateException e) { // Expected. } - assertEquals(0, digestCalls.get()); // No digest calls made for directory. + assertThat(digestCalls.get()).isEqualTo(0); // No digest calls made for directory. Path nonexistent = fs.getPath("/root/noexist"); try { - assertNull(valueForPath(nonexistent).getDigest()); + assertThat(valueForPath(nonexistent).getDigest()).isNull(); fail(); } catch (IllegalStateException e) { // Expected. } - assertEquals(0, digestCalls.get()); // No digest calls made for nonexistent file. + assertThat(digestCalls.get()).isEqualTo(0); // No digest calls made for nonexistent file. Path symlink = symlink("link", "/root/file"); value = valueForPath(symlink); - assertEquals(1, digestCalls.get()); + assertThat(digestCalls.get()).isEqualTo(1); // Symlink stores digest of target, not link. - assertArrayEquals(digest, value.getDigest()); - assertEquals(1, digestCalls.get()); + assertThat(value.getDigest()).isEqualTo(digest); + assertThat(digestCalls.get()).isEqualTo(1); digestCalls.set(0); - assertTrue(symlink.delete()); + assertThat(symlink.delete()).isTrue(); symlink = symlink("link", "/root/directory"); // Symlink stores digest of target, not link, for directories too. try { - assertNull(valueForPath(symlink).getDigest()); + assertThat(valueForPath(symlink).getDigest()).isNull(); fail(); } catch (IllegalStateException e) { // Expected. } - assertEquals(0, digestCalls.get()); + assertThat(digestCalls.get()).isEqualTo(0); } @Test @@ -944,10 +939,11 @@ public class FileFunctionTest { EvaluationResult<FileValue> result = driver.evaluate( ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()) + assertThat(errorInfo.getException()) + .hasMessageThat() .contains("file /root/a/b exists but its parent path /root/a isn't an existing directory"); } @@ -961,11 +957,11 @@ public class FileFunctionTest { EvaluationResult<FileValue> result = driver.evaluate( ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()).contains("encountered error 'nope'"); - assertThat(errorInfo.getException().getMessage()).contains("/root/a is no longer a file"); + assertThat(errorInfo.getException()).hasMessageThat().contains("encountered error 'nope'"); + assertThat(errorInfo.getException()).hasMessageThat().contains("/root/a is no longer a file"); } @Test @@ -989,12 +985,14 @@ public class FileFunctionTest { EvaluationResult<FileValue> result = driver.evaluate( ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()) + assertThat(errorInfo.getException()) + .hasMessageThat() .contains("encountered error 'isReadable failed'"); - assertThat(errorInfo.getException().getMessage()) + assertThat(errorInfo.getException()) + .hasMessageThat() .contains("/root/unreadable is no longer a file"); } @@ -1058,7 +1056,7 @@ public class FileFunctionTest { SequentialBuildDriver driver = makeDriver(); EvaluationResult<FileValue> result = driver.evaluate(keys, /*keepGoing=*/ true, DEFAULT_THREAD_COUNT, eventHandler); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); for (SkyKey key : keys) { ErrorInfo errorInfo = result.getError(key); // FileFunction detects symlink cycles explicitly. @@ -1128,10 +1126,10 @@ public class FileFunctionTest { FileValue b2 = (FileValue) ois.readObject(); FileValue c2 = (FileValue) ois.readObject(); - assertEquals(a, a2); - assertEquals(b, b2); - assertEquals(c, c2); - assertFalse(a2.equals(b2)); + assertThat(a2).isEqualTo(a); + assertThat(b2).isEqualTo(b); + assertThat(c2).isEqualTo(c); + assertThat(a2.equals(b2)).isFalse(); } finally { Path.setFileSystemForSerialization(oldFileSystem); } @@ -1228,14 +1226,14 @@ public class FileFunctionTest { } EvaluationResult<FileValue> result = driver.evaluate(keys, /*keepGoing=*/ true, DEFAULT_THREAD_COUNT, eventHandler); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); for (SkyKey key : errorKeys) { ErrorInfo errorInfo = result.getError(key); // FileFunction detects infinite symlink expansion explicitly. assertThat(errorInfo.getCycleInfo()).isEmpty(); FileSymlinkInfiniteExpansionException fsiee = (FileSymlinkInfiniteExpansionException) errorInfo.getException(); - assertThat(fsiee.getMessage()).contains("Infinite symlink expansion"); + assertThat(fsiee).hasMessageThat().contains("Infinite symlink expansion"); assertThat(fsiee.getChain()).containsExactlyElementsIn(expectedChain).inOrder(); } // Check that the unique symlink expansion error was reported exactly once. @@ -1269,8 +1267,8 @@ public class FileFunctionTest { Path ancestor = directory("this/is/an/ancestor"); Path parent = ancestor.getChild("parent"); Path child = parent.getChild("child"); - assertFalse(valueForPath(parent).exists()); - assertFalse(valueForPath(child).exists()); + assertThat(valueForPath(parent).exists()).isFalse(); + assertThat(valueForPath(child).exists()).isFalse(); } private void checkRealPath(String pathString) throws Exception { @@ -1288,9 +1286,8 @@ public class FileFunctionTest { fail(String.format("Evaluation error for %s: %s", key, result.getError())); } FileValue fileValue = (FileValue) result.get(key); - assertEquals( - pkgRoot.getRelative(expectedRealPathString).toString(), - fileValue.realRootedPath().asPath().toString()); + assertThat(fileValue.realRootedPath().asPath().toString()) + .isEqualTo(pkgRoot.getRelative(expectedRealPathString).toString()); } /** @@ -1523,11 +1520,15 @@ public class FileFunctionTest { } SkyValue newValue = result.get(key); - assertTrue( - String.format( - "Changing the contents of %s %s should%s change the value for file %s.", - isFile ? "file" : "directory", changedPathString, changes ? "" : " not", pathString), - changes != newValue.equals(oldValue)); + assertWithMessage( + String.format( + "Changing the contents of %s %s should%s change the value for file %s.", + isFile ? "file" : "directory", + changedPathString, + changes ? "" : " not", + pathString)) + .that(changes != newValue.equals(oldValue)) + .isTrue(); // Restore the original file. undoCallback.run(); @@ -1545,9 +1546,10 @@ public class FileFunctionTest { result = driver.evaluate( ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse( - "Did not expect error while evaluating " + pathString + ", got " + result.get(key), - result.hasError()); + assertWithMessage( + "Did not expect error while evaluating " + pathString + ", got " + result.get(key)) + .that(result.hasError()) + .isFalse(); return filesSeen(driver.getGraphForTesting()); } @@ -1562,12 +1564,13 @@ public class FileFunctionTest { result = driver.evaluate( ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue( - "Expected error while evaluating " + pathString + ", got " + result.get(key), - result.hasError()); - assertTrue( - !Iterables.isEmpty(result.getError().getCycleInfo()) - || result.getError().getException() != null); + assertWithMessage("Expected error while evaluating " + pathString + ", got " + result.get(key)) + .that(result.hasError()) + .isTrue(); + assertThat( + !Iterables.isEmpty(result.getError().getCycleInfo()) + || result.getError().getException() != null) + .isTrue(); return filesSeen(driver.getGraphForTesting()); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java index 949f09b168..91b1a65144 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java @@ -352,7 +352,8 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { SkyKey key = FilesetEntryValue.key(params); EvaluationResult<SkyValue> result = eval(key); assertThat(result.hasError()).isTrue(); - assertThat(result.getError(key).getException().getMessage()) + assertThat(result.getError(key).getException()) + .hasMessageThat() .contains("'foo/dir' crosses package boundary into package rooted at foo/dir/subpkg"); break; default: @@ -438,7 +439,8 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { SkyKey key = FilesetEntryValue.key(params); EvaluationResult<SkyValue> result = eval(key); assertThat(result.hasError()).isTrue(); - assertThat(result.getError(key).getException().getMessage()) + assertThat(result.getError(key).getException()) + .hasMessageThat() .contains( "'foo/dir_sym' crosses package boundary into package rooted at foo/dir_sym/subpkg"); break; @@ -530,7 +532,8 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { SkyKey key = FilesetEntryValue.key(params); EvaluationResult<SkyValue> result = eval(key); assertThat(result.hasError()).isTrue(); - assertThat(result.getError(key).getException().getMessage()) + assertThat(result.getError(key).getException()) + .hasMessageThat() .contains("'foo' crosses package boundary into package rooted at foo/subpkg"); break; default: 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 74e7c776e5..515096105b 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 @@ -14,10 +14,8 @@ package com.google.devtools.build.lib.skyframe; 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.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -162,7 +160,7 @@ public class FilesystemValueCheckerTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); @@ -179,7 +177,7 @@ public class FilesystemValueCheckerTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); } @@ -220,16 +218,16 @@ public class FilesystemValueCheckerTest { EvaluationResult<FileValue> result = driver.evaluate( allKeys, false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); FileValue symlinkValue = result.get(symlinkKey); FileValue fooValue = result.get(fooKey); - assertTrue(symlinkValue.toString(), symlinkValue.isSymlink()); + assertWithMessage(symlinkValue.toString()).that(symlinkValue.isSymlink()).isTrue(); // Digest is not always available, so use size as a proxy for contents. - assertEquals(fooValue.getSize(), symlinkValue.getSize()); + assertThat(symlinkValue.getSize()).isEqualTo(fooValue.getSize()); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); // Before second build, move sym1 to point to sym2. - assertTrue(sym1.delete()); + assertThat(sym1.delete()).isTrue(); FileSystemUtils.ensureSymbolicLink(sym1, sym2); assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), sym1FileStateKey); @@ -240,24 +238,24 @@ public class FilesystemValueCheckerTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), sym1FileStateKey); // Before third build, move sym1 back to original (so change pruning will prevent signaling of // its parents, but change symlink for real. - assertTrue(sym1.delete()); + assertThat(sym1.delete()).isTrue(); FileSystemUtils.ensureSymbolicLink(sym1, path); - assertTrue(symlink.delete()); + assertThat(symlink.delete()).isTrue(); FileSystemUtils.writeContentAsLatin1(symlink, "new symlink contents"); assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), symlinkFileStateKey); differencer.invalidate(ImmutableList.of(symlinkFileStateKey)); result = driver.evaluate( allKeys, false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); symlinkValue = result.get(symlinkKey); - assertFalse(symlinkValue.toString(), symlinkValue.isSymlink()); - assertEquals(fooValue, result.get(fooKey)); + assertWithMessage(symlinkValue.toString()).that(symlinkValue.isSymlink()).isFalse(); + assertThat(result.get(fooKey)).isEqualTo(fooValue); assertThat(symlinkValue.getSize()).isNotEqualTo(fooValue.getSize()); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); } @@ -282,7 +280,7 @@ public class FilesystemValueCheckerTest { EvaluationResult<SkyValue> result = driver.evaluate( skyKeys, false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); @@ -296,7 +294,7 @@ public class FilesystemValueCheckerTest { result = driver.evaluate( skyKeys, false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); } @@ -315,7 +313,7 @@ public class FilesystemValueCheckerTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); fs.readlinkThrowsIoException = false; FilesystemValueChecker checker = new FilesystemValueChecker(null, null); @@ -340,7 +338,7 @@ public class FilesystemValueCheckerTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); FilesystemValueChecker checker = new FilesystemValueChecker(null, null); Diff diff = getDirtyFilesystemKeys(evaluator, checker); @@ -377,10 +375,11 @@ public class FilesystemValueCheckerTest { new TestAction( Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out2)), forceDigests))); - assertFalse( - driver - .evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE) - .hasError()); + assertThat( + driver + .evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE) + .hasError()) + .isFalse(); assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty(); @@ -460,10 +459,11 @@ public class FilesystemValueCheckerTest { actionKeyLast, actionValueWithEmptyDirectory(last))); - assertFalse( - driver - .evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE) - .hasError()); + assertThat( + driver + .evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE) + .hasError()) + .isFalse(); assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty(); 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 ef865acbff..27086159d6 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,8 +14,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Functions; @@ -333,21 +331,9 @@ public abstract class GlobFunctionTest { private void assertGlobsEqual(String pattern1, String pattern2) throws Exception { GlobValue value1 = runGlob(false, pattern1); GlobValue value2 = runGlob(false, pattern2); - assertEquals( - "GlobValues " - + value1.getMatches() - + " and " - + value2.getMatches() - + " should be equal. " - + "Patterns: " - + pattern1 - + "," - + pattern2, - value1, - value2); - // Just to be paranoid: - assertEquals(value1, value1); - assertEquals(value2, value2); + new EqualsTester() + .addEqualityGroup(value1, value2) + .testEquals(); } private GlobValue runGlob(boolean excludeDirs, String pattern) throws Exception { @@ -457,7 +443,7 @@ public abstract class GlobFunctionTest { @Test public void testMatchesCallWithNoCache() { - assertTrue(UnixGlob.matches("*a*b", "CaCb", null)); + assertThat(UnixGlob.matches("*a*b", "CaCb", null)).isTrue(); } @Test @@ -585,10 +571,10 @@ public abstract class GlobFunctionTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()).contains(expectedMessage); + assertThat(errorInfo.getException()).hasMessageThat().contains(expectedMessage); } @Test @@ -612,10 +598,10 @@ public abstract class GlobFunctionTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()).contains(expectedMessage); + assertThat(errorInfo.getException()).hasMessageThat().contains(expectedMessage); } @Test @@ -685,10 +671,10 @@ public abstract class GlobFunctionTest { false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class); - assertThat(errorInfo.getException().getMessage()).contains(expectedMessage); + assertThat(errorInfo.getException()).hasMessageThat().contains(expectedMessage); } @Test 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 ebb609d54a..da738d6220 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,9 +15,6 @@ package com.google.devtools.build.lib.skyframe; 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.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Predicates; @@ -102,7 +99,7 @@ public class PackageFunctionTest extends BuildViewTestCase { fail(result.getError(skyKey).getException().getMessage()); } PackageValue value = result.get(skyKey); - assertFalse(value.getPackage().containsErrors()); + assertThat(value.getPackage().containsErrors()).isFalse(); return value; } @@ -171,7 +168,7 @@ public class PackageFunctionTest extends BuildViewTestCase { + "an existing directory"; EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); String errorMessage = errorInfo.getException().getMessage(); assertThat(errorMessage).contains("Inconsistent filesystem operations"); @@ -207,7 +204,7 @@ public class PackageFunctionTest extends BuildViewTestCase { String expectedMessage = "/workspace/foo/bar/baz is no longer an existing directory"; EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); String errorMessage = errorInfo.getException().getMessage(); assertThat(errorMessage).contains("Inconsistent filesystem operations"); @@ -229,7 +226,7 @@ public class PackageFunctionTest extends BuildViewTestCase { String expectedMessage = "Encountered error 'Directory is not readable'"; EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); String errorMessage = errorInfo.getException().getMessage(); assertThat(errorMessage).contains("Inconsistent filesystem operations"); @@ -468,7 +465,7 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//test/skylark")); EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); String expectedMsg = "error loading package 'test/skylark': " + "Extension file not found. Unable to load file '//test/skylark:bad_extension.bzl': " @@ -493,7 +490,7 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//test/skylark")); EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); assertThat(errorInfo.getException()) .hasMessage("error loading package 'test/skylark': Extension file not found. " @@ -516,9 +513,9 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//test/skylark")); EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skyKey); - assertEquals(skyKey, errorInfo.getRootCauseOfException()); + assertThat(errorInfo.getRootCauseOfException()).isEqualTo(skyKey); assertThat(errorInfo.getException()) .hasMessage( "error loading package 'test/skylark': Encountered error while reading extension " @@ -535,7 +532,7 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo")); EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); assertContainsEvent("nope"); } @@ -571,8 +568,8 @@ public class PackageFunctionTest extends BuildViewTestCase { EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter); - assertFalse(result.hasError()); - assertTrue(result.get(skyKey).getPackage().containsErrors()); + assertThat(result.hasError()).isFalse(); + assertThat(result.get(skyKey).getPackage().containsErrors()).isTrue(); } // Regression test for the two ugly consequences of a bug where GlobFunction incorrectly matched @@ -588,7 +585,7 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo")); PackageValue value = validPackage(skyKey); - assertFalse(value.getPackage().containsErrors()); + assertThat(value.getPackage().containsErrors()).isFalse(); assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt"); try { value.getPackage().getTarget("dangling.txt"); @@ -604,7 +601,7 @@ public class PackageFunctionTest extends BuildViewTestCase { ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), rootDirectory); value = validPackage(skyKey); - assertFalse(value.getPackage().containsErrors()); + assertThat(value.getPackage().containsErrors()).isFalse(); assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt"); try { value.getPackage().getTarget("dangling.txt"); @@ -620,7 +617,7 @@ public class PackageFunctionTest extends BuildViewTestCase { ModifiedFileSet.builder().modify(PathFragment.create("foo/nope")).build(), rootDirectory); PackageValue newValue = validPackage(skyKey); - assertFalse(newValue.getPackage().containsErrors()); + assertThat(newValue.getPackage().containsErrors()).isFalse(); assertThat(newValue.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt"); // Another consequence of the bug is that change pruning would incorrectly cut off changes that // caused a dangling symlink potentially matched by a glob to come into existence. @@ -641,7 +638,7 @@ public class PackageFunctionTest extends BuildViewTestCase { SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo")); PackageValue value = validPackage(skyKey); - assertFalse(value.getPackage().containsErrors()); + assertThat(value.getPackage().containsErrors()).isFalse(); assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched"); try { value.getPackage().getTarget("-matched"); @@ -656,7 +653,7 @@ public class PackageFunctionTest extends BuildViewTestCase { ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), rootDirectory); value = validPackage(skyKey); - assertFalse(value.getPackage().containsErrors()); + assertThat(value.getPackage().containsErrors()).isFalse(); assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched"); try { value.getPackage().getTarget("-matched"); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java index ff5b2bdeee..7e770ffe81 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java @@ -14,11 +14,8 @@ package com.google.devtools.build.lib.skyframe; +import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -174,18 +171,18 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { public void testNoBuildFile() throws Exception { scratch.file("parentpackage/nobuildfile/foo.txt"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/nobuildfile"); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.NO_BUILD_FILE, packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.NO_BUILD_FILE); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } @Test public void testNoBuildFileAndNoParentPackage() throws Exception { scratch.file("noparentpackage/foo.txt"); PackageLookupValue packageLookupValue = lookupPackage("noparentpackage"); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.NO_BUILD_FILE, packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.NO_BUILD_FILE); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } @Test @@ -194,9 +191,9 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { deletedPackages.set(ImmutableSet.of( PackageIdentifier.createInMainRepo("parentpackage/deletedpackage"))); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/deletedpackage"); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.DELETED_PACKAGE, packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.DELETED_PACKAGE); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } @@ -211,9 +208,9 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { ImmutableSet<String> pkgs = ImmutableSet.of("blacklisted/subdir", "blacklisted"); for (String pkg : pkgs) { PackageLookupValue packageLookupValue = lookupPackage(pkg); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.DELETED_PACKAGE, packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.DELETED_PACKAGE); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } scratch.overwriteFile("config/blacklisted.txt", "not_blacklisted"); @@ -223,7 +220,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { differencer.invalidate(ImmutableSet.of(FileStateValue.key(rootedBlacklist))); for (String pkg : pkgs) { PackageLookupValue packageLookupValue = lookupPackage(pkg); - assertTrue(packageLookupValue.packageExists()); + assertThat(packageLookupValue.packageExists()).isTrue(); } } @@ -231,38 +228,36 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { public void testInvalidPackageName() throws Exception { scratch.file("parentpackage/invalidpackagename%42/BUILD"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/invalidpackagename%42"); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.INVALID_PACKAGE_NAME, - packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.INVALID_PACKAGE_NAME); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } @Test public void testDirectoryNamedBuild() throws Exception { scratch.dir("parentpackage/isdirectory/BUILD"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/isdirectory"); - assertFalse(packageLookupValue.packageExists()); - assertEquals(ErrorReason.NO_BUILD_FILE, - packageLookupValue.getErrorReason()); - assertNotNull(packageLookupValue.getErrorMsg()); + assertThat(packageLookupValue.packageExists()).isFalse(); + assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.NO_BUILD_FILE); + assertThat(packageLookupValue.getErrorMsg()).isNotNull(); } @Test public void testEverythingIsGood_BUILD() throws Exception { scratch.file("parentpackage/everythinggood/BUILD"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); - assertTrue(packageLookupValue.packageExists()); - assertEquals(rootDirectory, packageLookupValue.getRoot()); - assertEquals(BuildFileName.BUILD, packageLookupValue.getBuildFileName()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @Test public void testEverythingIsGood_BUILD_bazel() throws Exception { scratch.file("parentpackage/everythinggood/BUILD.bazel"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); - assertTrue(packageLookupValue.packageExists()); - assertEquals(rootDirectory, packageLookupValue.getRoot()); - assertEquals(BuildFileName.BUILD_DOT_BAZEL, packageLookupValue.getBuildFileName()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD_DOT_BAZEL); } @Test @@ -270,9 +265,9 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.file("parentpackage/everythinggood/BUILD"); scratch.file("parentpackage/everythinggood/BUILD.bazel"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); - assertTrue(packageLookupValue.packageExists()); - assertEquals(rootDirectory, packageLookupValue.getRoot()); - assertEquals(BuildFileName.BUILD_DOT_BAZEL, packageLookupValue.getBuildFileName()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD_DOT_BAZEL); } @Test @@ -282,18 +277,18 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { // BUILD file in the first package path should be preferred to BUILD.bazel in the second. PackageLookupValue packageLookupValue = lookupPackage("foo"); - assertTrue(packageLookupValue.packageExists()); - assertEquals(emptyPackagePath, packageLookupValue.getRoot()); - assertEquals(BuildFileName.BUILD, packageLookupValue.getBuildFileName()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(emptyPackagePath); + assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @Test public void testEmptyPackageName() throws Exception { scratch.file("BUILD"); PackageLookupValue packageLookupValue = lookupPackage(""); - assertTrue(packageLookupValue.packageExists()); - assertEquals(rootDirectory, packageLookupValue.getRoot()); - assertEquals(BuildFileName.BUILD, packageLookupValue.getBuildFileName()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @Test @@ -301,8 +296,8 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.overwriteFile("WORKSPACE"); PackageLookupValue packageLookupValue = lookupPackage( PackageIdentifier.createInMainRepo("external")); - assertTrue(packageLookupValue.packageExists()); - assertEquals(rootDirectory, packageLookupValue.getRoot()); + assertThat(packageLookupValue.packageExists()).isTrue(); + assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); } @Test @@ -340,11 +335,11 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { // First, use the correct label. PackageLookupValue packageLookupValue = lookupPackage(PackageIdentifier.create("@local", PathFragment.EMPTY_FRAGMENT)); - assertTrue(packageLookupValue.packageExists()); + assertThat(packageLookupValue.packageExists()).isTrue(); // Then, use the incorrect label. packageLookupValue = lookupPackage(PackageIdentifier.createInMainRepo("local/repo")); - assertEquals(expectedPackageExists, packageLookupValue.packageExists()); + assertThat(packageLookupValue.packageExists()).isEqualTo(expectedPackageExists); } /** diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java index df35718a42..7a732129f3 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java @@ -13,12 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import com.google.devtools.build.lib.cmdline.PackageIdentifier; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -38,9 +36,9 @@ public class PackageProgressReceiverTest { progress.startReadPackage(id); String activity = progress.progressState().getSecond(); - assertTrue( - "Unfinished package '" + id + "' should be visible in activity: " + activity, - activity.contains(id.toString())); + assertWithMessage("Unfinished package '" + id + "' should be visible in activity: " + activity) + .that(activity.contains(id.toString())) + .isTrue(); } @Test @@ -54,11 +52,13 @@ public class PackageProgressReceiverTest { String state = progress.progressState().getFirst(); String activity = progress.progressState().getSecond(); - assertFalse( - "Finished package '" + id + "' should not be visible in activity: " + activity, - activity.contains(id.toString())); - assertTrue( - "Number of completed packages should be visible in state", state.contains("1 package")); + assertWithMessage( + "Finished package '" + id + "' should not be visible in activity: " + activity) + .that(activity.contains(id.toString())) + .isFalse(); + assertWithMessage("Number of completed packages should be visible in state") + .that(state.contains("1 package")) + .isTrue(); } @Test @@ -71,7 +71,7 @@ public class PackageProgressReceiverTest { progress.startReadPackage(id); progress.doneReadPackage(id); progress.reset(); - assertEquals(defaultState, progress.progressState().getFirst()); - assertEquals(defaultActivity, progress.progressState().getSecond()); + assertThat(progress.progressState().getFirst()).isEqualTo(defaultState); + assertThat(progress.progressState().getSecond()).isEqualTo(defaultActivity); } } 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 97446fffbb..fe8c4037f3 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 @@ -15,8 +15,7 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -194,7 +193,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(createBuilder(DEFAULT_NUM_JOBS, true), pear); assertThat(recorder.actionExecutedEvents).hasSize(1); - assertEquals(action, recorder.actionExecutedEvents.get(0).getAction()); + assertThat(recorder.actionExecutedEvents.get(0).getAction()).isEqualTo(action); } @Test @@ -480,7 +479,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { BuildKind kind) { // Check that we really did build all the targets. for (Artifact file : targets) { - assertTrue(file.getPath().exists()); + assertThat(file.getPath().exists()).isTrue(); } // Check that each action was executed the right number of times for (Counter counter : counters) { @@ -554,12 +553,15 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(foo, bar); fail(); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("TestAction failed due to exception: foo action failed"); + assertThat(e) + .hasMessageThat() + .contains("TestAction failed due to exception: foo action failed"); assertContainsEvent("TestAction failed due to exception: foo action failed"); } - assertTrue("bar action not finished, yet buildArtifacts has completed.", - finished[0]); + assertWithMessage("bar action not finished, yet buildArtifacts has completed.") + .that(finished[0]) + .isTrue(); } @Test @@ -577,7 +579,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(foo); fail("Builder failed to detect cyclic action graph"); } catch (BuildFailedException e) { - assertEquals(CYCLE_MSG, e.getMessage()); + assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG); } } @@ -590,7 +592,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(foo); fail("Builder failed to detect cyclic action graph"); } catch (BuildFailedException e) { - assertEquals(CYCLE_MSG, e.getMessage()); + assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG); } } @@ -612,7 +614,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(foo1, foo2); fail("Builder failed to detect cyclic action graph"); } catch (BuildFailedException e) { - assertEquals(CYCLE_MSG, e.getMessage()); + assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG); } } @@ -634,7 +636,7 @@ public class ParallelBuilderTest extends TimestampBuilderTestCase { buildArtifacts(foo); fail("Builder failed to detect cyclic action graph"); } catch (BuildFailedException e) { - assertEquals(CYCLE_MSG, e.getMessage()); + assertThat(e).hasMessageThat().isEqualTo(CYCLE_MSG); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java index 8786b42af3..535d4dadb0 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java @@ -15,8 +15,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.WalkableGraphUtils.exists; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; @@ -61,11 +59,13 @@ public class PrepareDepsOfPatternsFunctionSmartNegationTest extends BuildViewTes patternSequence, /*successExpected=*/ true, /*keepGoing=*/ true); // Then the graph contains package values for "@//foo" and "@//foo/foo", - assertTrue(exists(PackageValue.key(PackageIdentifier.parse("@//foo")), walkableGraph)); - assertTrue(exists(PackageValue.key(PackageIdentifier.parse("@//foo/foo")), walkableGraph)); + assertThat(exists(PackageValue.key(PackageIdentifier.parse("@//foo")), walkableGraph)).isTrue(); + assertThat(exists(PackageValue.key(PackageIdentifier.parse("@//foo/foo")), walkableGraph)) + .isTrue(); // But the graph does not contain a value for the target "@//foo/foo:foofoo". - assertFalse(exists(getKeyForLabel(Label.create("@//foo/foo", "foofoo")), walkableGraph)); + assertThat(exists(getKeyForLabel(Label.create("@//foo/foo", "foofoo")), walkableGraph)) + .isFalse(); } @Test @@ -105,14 +105,15 @@ public class PrepareDepsOfPatternsFunctionSmartNegationTest extends BuildViewTes patternSequence, /*successExpected=*/ true, /*keepGoing=*/ true); // Then the graph contains a package value for "@//foo", - assertTrue(exists(PackageValue.key(PackageIdentifier.parse("@//foo")), walkableGraph)); + assertThat(exists(PackageValue.key(PackageIdentifier.parse("@//foo")), walkableGraph)).isTrue(); // But no package value for "@//foo/foo", - assertFalse(exists(PackageValue.key(PackageIdentifier.parse("@//foo/foo")), walkableGraph)); + assertThat(exists(PackageValue.key(PackageIdentifier.parse("@//foo/foo")), walkableGraph)) + .isFalse(); // And the graph does not contain a value for the target "@//foo/foo:foofoo". Label label = Label.create("@//foo/foo", "foofoo"); - assertFalse(exists(getKeyForLabel(label), walkableGraph)); + assertThat(exists(getKeyForLabel(label), walkableGraph)).isFalse(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionTest.java index 0afcbed94f..13bae04250 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionTest.java @@ -16,10 +16,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult; import static com.google.devtools.build.skyframe.WalkableGraphUtils.exists; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; @@ -64,7 +60,7 @@ public class PrepareDepsOfPatternsFunctionTest extends BuildViewTestCase { assertValidValue(walkableGraph, getKeyForLabel(Label.create("@//foo", "foo"))); // And the graph does not contain a value for the target "@//foo:foo2". - assertFalse(exists(getKeyForLabel(Label.create("@//foo", "foo2")), walkableGraph)); + assertThat(exists(getKeyForLabel(Label.create("@//foo", "foo2")), walkableGraph)).isFalse(); } @Test @@ -109,7 +105,7 @@ public class PrepareDepsOfPatternsFunctionTest extends BuildViewTestCase { WalkableGraph walkableGraph = getGraphFromPatternsEvaluation(patternSequence); // Then the graph does not contain an entry for ":foo", - assertFalse(exists(getKeyForLabel(Label.create("@//foo", "foo")), walkableGraph)); + assertThat(exists(getKeyForLabel(Label.create("@//foo", "foo")), walkableGraph)).isFalse(); } @Test @@ -191,7 +187,7 @@ public class PrepareDepsOfPatternsFunctionTest extends BuildViewTestCase { assertContainsEvent("Skipping '" + bogusPattern + "': "); // And then the graph contains a value for the legit target pattern's target "@//foo:foo". - assertTrue(exists(getKeyForLabel(Label.create("@//foo", "foo")), walkableGraph)); + assertThat(exists(getKeyForLabel(Label.create("@//foo", "foo")), walkableGraph)).isTrue(); } // Helpers: @@ -267,19 +263,19 @@ public class PrepareDepsOfPatternsFunctionTest extends BuildViewTestCase { private static void assertValidValue( WalkableGraph graph, SkyKey key, boolean expectTransitiveException) throws InterruptedException { - assertNotNull(graph.getValue(key)); + assertThat(graph.getValue(key)).isNotNull(); if (expectTransitiveException) { - assertNotNull(graph.getException(key)); + assertThat(graph.getException(key)).isNotNull(); } else { - assertNull(graph.getException(key)); + assertThat(graph.getException(key)).isNull(); } } private static Exception assertException(WalkableGraph graph, SkyKey key) throws InterruptedException { - assertNull(graph.getValue(key)); + assertThat(graph.getValue(key)).isNull(); Exception exception = graph.getException(key); - assertNotNull(exception); + assertThat(exception).isNotNull(); return exception; } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java index 1602f4a62a..69a46cc02c 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java @@ -16,8 +16,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.WalkableGraphUtils.exists; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -189,18 +187,21 @@ public class PrepareDepsOfTargetsUnderDirectoryFunctionTest extends BuildViewTes // Also, the computation graph does not contain a cached value for "a/b". WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph()); - assertFalse( - exists( - createPrepDepsKey(rootDirectory, excludedPathFragment, ImmutableSet.<PathFragment>of()), - graph)); + assertThat( + exists( + createPrepDepsKey( + rootDirectory, excludedPathFragment, ImmutableSet.<PathFragment>of()), + graph)) + .isFalse(); // And the computation graph does contain a cached value for "a/c" with the empty set excluded, // because that key was evaluated. - assertTrue( - exists( - createPrepDepsKey( - rootDirectory, PathFragment.create("a/c"), ImmutableSet.<PathFragment>of()), - graph)); + assertThat( + exists( + createPrepDepsKey( + rootDirectory, PathFragment.create("a/c"), ImmutableSet.<PathFragment>of()), + graph)) + .isTrue(); } @Test 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 2aa91f699d..2d121cbe1e 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 @@ -636,7 +636,8 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe SkyKey key = rftvSkyKey(traversalRoot); EvaluationResult<SkyValue> result = eval(key); assertThat(result.hasError()).isTrue(); - assertThat(result.getError().getException().getMessage()) + assertThat(result.getError().getException()) + .hasMessageThat() .contains("crosses package boundary into package rooted at"); break; default: @@ -811,7 +812,8 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe assertThat(result.hasError()).isTrue(); ErrorInfo error = result.getError(key); assertThat(error.isTransient()).isFalse(); - assertThat(error.getException().getMessage()) + assertThat(error.getException()) + .hasMessageThat() .contains("Generated directory a/b/c conflicts with package under the same path."); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java index 6c7befe128..474ab93339 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java @@ -15,9 +15,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.WalkableGraphUtils.exists; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -93,7 +90,7 @@ public class RecursivePkgFunctionTest extends BuildViewTestCase { scratch.file("a/b/c/BUILD"); RecursivePkgValue value = buildRecursivePkgValue(rootDirectory, PathFragment.create("a/b/c/BUILD")); - assertTrue(value.getPackages().isEmpty()); + assertThat(value.getPackages().isEmpty()).isTrue(); } @Test @@ -108,11 +105,11 @@ public class RecursivePkgFunctionTest extends BuildViewTestCase { RecursivePkgValue valueForRoot1 = buildRecursivePkgValue(root1, PathFragment.create("a")); String root1Pkg = Iterables.getOnlyElement(valueForRoot1.getPackages()); - assertEquals("a", root1Pkg); + assertThat(root1Pkg).isEqualTo("a"); RecursivePkgValue valueForRoot2 = buildRecursivePkgValue(root2, PathFragment.create("a")); String root2Pkg = Iterables.getOnlyElement(valueForRoot2.getPackages()); - assertEquals("a/b", root2Pkg); + assertThat(root2Pkg).isEqualTo("a/b"); } @Test @@ -139,19 +136,21 @@ public class RecursivePkgFunctionTest extends BuildViewTestCase { // Also, the computation graph does not contain a cached value for "a/b". WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph()); - assertFalse( - exists( - buildRecursivePkgKey( - rootDirectory, excludedPathFragment, ImmutableSet.<PathFragment>of()), - graph)); + assertThat( + exists( + buildRecursivePkgKey( + rootDirectory, excludedPathFragment, ImmutableSet.<PathFragment>of()), + graph)) + .isFalse(); // And the computation graph does contain a cached value for "a/c" with the empty set excluded, // because that key was evaluated. - assertTrue( - exists( - buildRecursivePkgKey( - rootDirectory, PathFragment.create("a/c"), ImmutableSet.<PathFragment>of()), - graph)); + assertThat( + exists( + buildRecursivePkgKey( + rootDirectory, PathFragment.create("a/c"), ImmutableSet.<PathFragment>of()), + graph)) + .isTrue(); } @Test @@ -177,9 +176,10 @@ public class RecursivePkgFunctionTest extends BuildViewTestCase { // Also, the computation graph contains a cached value for "a/b" with "a/b/c" excluded, because // "a/b/c" does live underneath "a/b". WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph()); - assertTrue( - exists( - buildRecursivePkgKey(rootDirectory, PathFragment.create("a/b"), excludedPaths), - graph)); + assertThat( + exists( + buildRecursivePkgKey(rootDirectory, PathFragment.create("a/b"), excludedPaths), + graph)) + .isTrue(); } } 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 89566b1b09..063c1dbc55 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,7 +14,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -74,7 +73,7 @@ public class SkyframeLabelVisitorTest extends SkyframeLabelVisitorTestCase { scratch.file("unrelated/BUILD", "sh_library(name = 'unrelated')"); assertLabelsVisited( ImmutableSet.of("//bar:foo"), ImmutableSet.of("//bar:foo"), !EXPECT_ERROR, !KEEP_GOING); - assertTrue(sym1.delete()); + assertThat(sym1.delete()).isTrue(); FileSystemUtils.ensureSymbolicLink(sym1, sym2); syncPackages(); assertLabelsVisited( @@ -82,9 +81,9 @@ public class SkyframeLabelVisitorTest extends SkyframeLabelVisitorTestCase { ImmutableSet.of("//unrelated:unrelated"), !EXPECT_ERROR, !KEEP_GOING); - assertTrue(sym1.delete()); + assertThat(sym1.delete()).isTrue(); FileSystemUtils.ensureSymbolicLink(sym1, path); - assertTrue(symlink.delete()); + assertThat(symlink.delete()).isTrue(); symlink = scratch.file("bar/BUILD", "sh_library(name = 'bar')"); syncPackages(); assertLabelsVisited( @@ -349,7 +348,7 @@ public class SkyframeLabelVisitorTest extends SkyframeLabelVisitorTestCase { // This is expected for legacy blaze. } catch (RuntimeException re) { // This is expected for Skyframe blaze. - assertThat(re.getCause()).isInstanceOf(NullPointerException.class); + assertThat(re).hasCauseThat().isInstanceOf(NullPointerException.class); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java index 17f27ca56e..0b92f726ae 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.skyframe.WalkableGraphUtils.exists; -import static org.junit.Assert.assertNotSame; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -135,7 +134,7 @@ abstract public class SkyframeLabelVisitorTestCase extends PackageLoadingTestCas // Spawn a lot of threads to help uncover concurrency issues boolean result = visitor.sync(reporter, startingLabels, keepGoing, /*parallelThreads=*/ 200); - assertNotSame(expectError, result); + assertThat(result).isNotSameAs(expectError); assertExpectedTargets(expectedLabels, startingLabels); } @@ -209,7 +208,7 @@ abstract public class SkyframeLabelVisitorTestCase extends PackageLoadingTestCas // Spawn a lot of threads to help uncover concurrency issues boolean result = visitor.sync(reporter, labels, keepGoing, 200); - assertNotSame(expectError, result); + assertThat(result).isNotSameAs(expectError); assertThat(getVisitedLabels(asLabelSet(startingLabels), skyframeExecutor)) .containsAllIn(asLabelSet(expectedLabels)); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java index 59a68c50d7..7a548becad 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java @@ -13,8 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -80,7 +79,7 @@ public class SkylarkFileContentHashTests extends BuildViewTestCase { @Test public void testHashInvariance() throws Exception { - assertEquals(getHash("pkg", "foo1"), getHash("pkg", "foo1")); + assertThat(getHash("pkg", "foo1")).isEqualTo(getHash("pkg", "foo1")); } @Test @@ -92,12 +91,12 @@ public class SkylarkFileContentHashTests extends BuildViewTestCase { "", "bar1 = rule(implementation = rule_impl)"); invalidatePackages(); - assertEquals(bar1, getHash("pkg", "bar1")); + assertThat(getHash("pkg", "bar1")).isEqualTo(bar1); } @Test public void testHashSameForRulesDefinedInSameFile() throws Exception { - assertEquals(getHash("pkg", "foo1"), getHash("pkg", "foo2")); + assertThat(getHash("pkg", "foo2")).isEqualTo(getHash("pkg", "foo1")); } @Test @@ -145,12 +144,12 @@ public class SkylarkFileContentHashTests extends BuildViewTestCase { "", "bar1 = rule(implementation = rule_impl)"); invalidatePackages(); - assertEquals(foo1, getHash("pkg", "foo1")); - assertEquals(foo2, getHash("pkg", "foo2")); + assertThat(getHash("pkg", "foo1")).isEqualTo(foo1); + assertThat(getHash("pkg", "foo2")).isEqualTo(foo2); } private void assertNotEquals(String hash, String hash2) { - assertFalse(hash.equals(hash2)); + assertThat(hash.equals(hash2)).isFalse(); } /** @@ -176,7 +175,7 @@ public class SkylarkFileContentHashTests extends BuildViewTestCase { EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), pkgLookupKey, /*keepGoing=*/ false, reporter); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); Collection<Target> targets = result.get(pkgLookupKey).getPackage().getTargets().values(); for (Target target : targets) { if (target.getName().equals(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 a386a8042c..602d097101 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 @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -174,8 +172,8 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { private void checkSuccessfulLookup(String label) throws Exception { SkyKey skylarkImportLookupKey = key(label); EvaluationResult<SkylarkImportLookupValue> result = get(skylarkImportLookupKey); - assertEquals(result.get(skylarkImportLookupKey).getDependency().getLabel().toString(), - label); + assertThat(label) + .isEqualTo(result.get(skylarkImportLookupKey).getDependency().getLabel().toString()); } @Test @@ -186,11 +184,13 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skylarkImportLookupKey); String errorMessage = errorInfo.getException().getMessage(); - assertEquals("Extension file not found. Unable to load package for '//pkg:ext.bzl': " - + "BUILD file not found on package path", errorMessage); + assertThat(errorMessage) + .isEqualTo( + "Extension file not found. Unable to load package for '//pkg:ext.bzl': " + + "BUILD file not found on package path"); } @Test @@ -203,11 +203,13 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skylarkImportLookupKey); String errorMessage = errorInfo.getException().getMessage(); - assertEquals("Extension file not found. Unable to load package for '//pkg:ext.bzl': " - + "BUILD file not found on package path", errorMessage); + assertThat(errorMessage) + .isEqualTo( + "Extension file not found. Unable to load package for '//pkg:ext.bzl': " + + "BUILD file not found on package path"); } @Test @@ -219,11 +221,13 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter); - assertTrue(result.hasError()); + assertThat(result.hasError()).isTrue(); ErrorInfo errorInfo = result.getError(skylarkImportLookupKey); String errorMessage = errorInfo.getException().getMessage(); - assertEquals("invalid target name 'oops<?>.bzl': " - + "target names may not contain non-printable characters: '\\x00'", errorMessage); + assertThat(errorMessage) + .isEqualTo( + "invalid target name 'oops<?>.bzl': " + + "target names may not contain non-printable characters: '\\x00'"); } @Test @@ -246,6 +250,6 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/ false, reporter); - assertFalse(result.hasError()); + assertThat(result.hasError()).isFalse(); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java index 5561adcf71..ce80ffc0a5 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java @@ -14,10 +14,7 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; @@ -36,19 +33,17 @@ import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; - +import java.io.IOException; +import java.util.Map; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; -import java.util.Map; - /** * Tests for {@link TargetMarkerFunction}. Unfortunately, we can't directly test - * TargetMarkerFunction as it uses PackageValues, and PackageFunction uses legacy stuff - * that isn't easily mockable. So our testing strategy is to make hacky calls to SkyframeExecutor. + * TargetMarkerFunction as it uses PackageValues, and PackageFunction uses legacy stuff that isn't + * easily mockable. So our testing strategy is to make hacky calls to SkyframeExecutor. */ @RunWith(JUnit4.class) public class TargetMarkerFunctionTest extends BuildViewTestCase { @@ -80,7 +75,7 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { reporter.addHandler(failFastHandler); ErrorInfo errorInfo = evaluationResult.getError(skyKey(labelName)); // Ensures that TargetFunction rethrows all transitive exceptions. - assertEquals(targetKey, Iterables.getOnlyElement(errorInfo.getRootCauses())); + assertThat(errorInfo.getRootCauses()).containsExactly(targetKey); return errorInfo.getException(); } @@ -100,7 +95,8 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { NoSuchTargetException exn = (NoSuchTargetException) getErrorFromTargetValue(labelName); // In the presence of b/12545745, the error message is different and comes from the // PackageFunction. - assertThat(exn.getMessage()) + assertThat(exn) + .hasMessageThat() .contains("Label '//a:b/c/foo.sh' crosses boundary of subpackage 'a/b'"); } @@ -109,7 +105,7 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { String labelName = "//no/such/package:target/withslash"; BuildFileNotFoundException exn = (BuildFileNotFoundException) getErrorFromTargetValue(labelName); - assertEquals(PackageIdentifier.createInMainRepo("no/such/package"), exn.getPackageId()); + assertThat(exn.getPackageId()).isEqualTo(PackageIdentifier.createInMainRepo("no/such/package")); String expectedMessage = "no such package 'no/such/package': BUILD file not found on " + "package path for 'no/such/package'"; @@ -124,10 +120,11 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { "genrule(name = 'conflict1', cmd = '', srcs = [], outs = ['conflict'])", "genrule(name = 'conflict2', cmd = '', srcs = [], outs = ['conflict'])"); NoSuchTargetException exn = (NoSuchTargetException) getErrorFromTargetValue("@//a:conflict1"); - assertThat(exn.getMessage()) + assertThat(exn) + .hasMessageThat() .contains("Target '//a:conflict1' contains an error and its package is in error"); - assertEquals("//a:conflict1", exn.getLabel().toString()); - assertTrue(exn.hasTarget()); + assertThat(exn.getLabel().toString()).isEqualTo("//a:conflict1"); + assertThat(exn.hasTarget()).isTrue(); } @Test @@ -138,7 +135,7 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { fs.stubStatIOException(subpackageBuildFile, new IOException("nope")); BuildFileNotFoundException exn = (BuildFileNotFoundException) getErrorFromTargetValue("//a:b/c"); - assertThat(exn.getMessage()).contains("nope"); + assertThat(exn).hasMessageThat().contains("nope"); } private static class CustomInMemoryFs extends InMemoryFileSystem { 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 3c274f91c5..4334b3e407 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,8 +14,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -30,17 +28,15 @@ import com.google.devtools.build.lib.testutil.TestSpec; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.UnixGlob; - +import java.io.IOException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; - /** - * These tests belong to {@link TimestampBuilderTest}, but they're in a - * separate class for now because they are a little slower. + * These tests belong to {@link TimestampBuilderTest}, but they're in a separate class for now + * because they are a little slower. */ @TestSpec(size = Suite.MEDIUM_TESTS) @RunWith(JUnit4.class) @@ -81,41 +77,41 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); cache = createCache(); button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt BlazeTestUtils.makeEmptyFile(optional.getPath()); button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt optional.getPath().delete(); button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built // Creating a new persistent cache does not cause a rebuild cache.save(); cache = createCache(); button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -128,27 +124,27 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); buildArtifacts(persistentBuilder(createCache()), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -162,30 +158,30 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // still not rebuilt + assertThat(button.pressed).isFalse(); // still not rebuilt FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content2"); button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); buildArtifacts(persistentBuilder(createCache()), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -204,11 +200,11 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Now create duplicate graph, with swapped order. clearActions(); @@ -219,7 +215,7 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button2.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button2.pressed); // still not rebuilt + assertThat(button2.pressed).isFalse(); // still not rebuilt } @Test @@ -232,7 +228,7 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built // action1 is cached using the cache key /goodbye. assertThat(cache.get(goodbye.getExecPathString())).isNotNull(); @@ -246,7 +242,7 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button2.pressed = false; buildArtifacts(persistentBuilder(cache), hello, goodbye2); - assertTrue(button2.pressed); // rebuilt + assertThat(button2.pressed).isTrue(); // rebuilt // action2 is cached using the cache key /hello. assertThat(cache.get(hello.getExecPathString())).isNotNull(); @@ -267,11 +263,11 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Now create duplicate graph, replacing "hello" with "hi". clearActions(); @@ -283,7 +279,7 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button2.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye2); - assertTrue(button2.pressed); // name changed. must rebuild. + assertThat(button2.pressed).isTrue(); // name changed. must rebuild. } @Test @@ -299,26 +295,26 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt FileSystemUtils.writeContentAsLatin1(hello.getPath(), "hello2"); button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); buildArtifacts(persistentBuilder(createCache()), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } /** @@ -337,18 +333,18 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent caches, including metadata cache does not cause // a rebuild cache.save(); Builder builder = persistentBuilder(createCache()); buildArtifacts(builder, goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -359,27 +355,27 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); buildArtifacts(persistentBuilder(createCache()), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -390,31 +386,32 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Creating a new persistent cache does not cause a rebuild cache.save(); // Remove filename index file. - assertTrue( - Iterables.getOnlyElement( - UnixGlob.forPath(cacheRoot).addPattern("filename_index*").globInterruptible()) - .delete()); + assertThat( + Iterables.getOnlyElement( + UnixGlob.forPath(cacheRoot).addPattern("filename_index*").globInterruptible()) + .delete()) + .isTrue(); // Now first cache creation attempt should cause IOException while renaming corrupted files. // Second attempt will initialize empty cache, causing rebuild. @@ -426,7 +423,7 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { } buildArtifacts(persistentBuilder(createCache()), hello); - assertTrue(button.pressed); // rebuilt due to the missing filename index + assertThat(button.pressed).isTrue(); // rebuilt due to the missing filename index } @Test @@ -437,22 +434,22 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(persistentBuilder(cache), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt cache.save(); @@ -467,14 +464,14 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { Artifact helloExtra = createDerivedArtifact("hello_extra"); Button buttonExtra = createActionButton(emptySet, Sets.newHashSet(helloExtra)); buildArtifacts(persistentBuilder(cache), helloExtra); - assertTrue(buttonExtra.pressed); // built + assertThat(buttonExtra.pressed).isTrue(); // built cache.save(); - assertTrue(indexPath.getFileSize() > indexCopy.getFileSize()); + assertThat(indexPath.getFileSize()).isGreaterThan(indexCopy.getFileSize()); // Validate current cache. buildArtifacts(persistentBuilder(createCache()), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Restore outdated file index. FileSystemUtils.copyFile(indexCopy, indexPath); @@ -485,11 +482,11 @@ public class TimestampBuilderMediumTest extends TimestampBuilderTestCase { createCache(); fail("Expected IOException"); } catch (IOException e) { - assertThat(e.getMessage()).contains("Failed action cache referential integrity check"); + assertThat(e).hasMessageThat().contains("Failed action cache referential integrity check"); } // Validate cache with incorrect (out-of-date) filename index. buildArtifacts(persistentBuilder(createCache()), hello); - assertTrue(button.pressed); // rebuilt due to the out-of-date index + assertThat(button.pressed).isTrue(); // rebuilt due to the out-of-date index } } 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 439b57e2db..d7ecec6d8a 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,9 +15,6 @@ package com.google.devtools.build.lib.skyframe; 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.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.Sets; @@ -47,11 +44,11 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(amnesiacBuilder(), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(amnesiacBuilder(), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt } // If we re-use the same builder (even an "amnesiac" builder), it remembers @@ -71,7 +68,7 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { counter.count = 0; buildArtifacts(amnesiacBuilder, hello, hello); - assertEquals(1, counter.count); // built only once + assertThat(counter.count).isEqualTo(1); // built only once } @Test @@ -101,17 +98,17 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt inMemoryCache.reset(); button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt } @Test @@ -124,31 +121,31 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt BlazeTestUtils.makeEmptyFile(optional.getPath()); button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt optional.getPath().delete(); button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -161,22 +158,22 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -192,27 +189,27 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt FileSystemUtils.touchFile(hello.getPath()); button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // still not rebuilt + assertThat(button.pressed).isFalse(); // still not rebuilt FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content2"); button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -223,11 +220,11 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertTrue(button.pressed); // built + assertThat(button.pressed).isTrue(); // built button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt // Changing the *output* file 'hello' causes 'action' to re-execute, to make things consistent // again. @@ -236,11 +233,11 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertTrue(button.pressed); // rebuilt + assertThat(button.pressed).isTrue(); // rebuilt button.pressed = false; buildArtifacts(cachingBuilder(), hello); - assertFalse(button.pressed); // not rebuilt + assertThat(button.pressed).isFalse(); // not rebuilt } @Test @@ -256,31 +253,31 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { button1.pressed = button2.pressed = false; buildArtifacts(cachingBuilder(), wazuup); - assertTrue(button1.pressed); // built wazuup - assertFalse(button2.pressed); // goodbye not built + assertThat(button1.pressed).isTrue(); // built wazuup + assertThat(button2.pressed).isFalse(); // goodbye not built button1.pressed = button2.pressed = false; buildArtifacts(cachingBuilder(), wazuup); - assertFalse(button1.pressed); // wazuup not rebuilt - assertFalse(button2.pressed); // goodbye not built + assertThat(button1.pressed).isFalse(); // wazuup not rebuilt + assertThat(button2.pressed).isFalse(); // goodbye not built button1.pressed = button2.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button1.pressed); // wazuup not rebuilt - assertTrue(button2.pressed); // built goodbye + assertThat(button1.pressed).isFalse(); // wazuup not rebuilt + assertThat(button2.pressed).isTrue(); // built goodbye button1.pressed = button2.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertFalse(button1.pressed); // wazuup not rebuilt - assertFalse(button2.pressed); // goodbye not rebuilt + assertThat(button1.pressed).isFalse(); // wazuup not rebuilt + assertThat(button2.pressed).isFalse(); // goodbye not rebuilt hello.getPath().setWritable(true); FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content"); button1.pressed = button2.pressed = false; buildArtifacts(cachingBuilder(), goodbye); - assertTrue(button1.pressed); // hello rebuilt - assertTrue(button2.pressed); // goodbye rebuilt + assertThat(button1.pressed).isTrue(); // hello rebuilt + assertThat(button2.pressed).isTrue(); // goodbye rebuilt } @Test @@ -297,15 +294,15 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { buildArtifacts(cachingBuilder(), anOutputFile, anotherOutputFile); - assertTrue(aButton.pressed); - assertTrue(anotherButton.pressed); + assertThat(aButton.pressed).isTrue(); + assertThat(anotherButton.pressed).isTrue(); aButton.pressed = anotherButton.pressed = false; buildArtifacts(cachingBuilder(), anOutputFile, anotherOutputFile); - assertFalse(aButton.pressed); - assertFalse(anotherButton.pressed); + assertThat(aButton.pressed).isFalse(); + assertThat(anotherButton.pressed).isFalse(); } @Test @@ -331,7 +328,7 @@ public class TimestampBuilderTest extends TimestampBuilderTestCase { buildArtifacts(amnesiacBuilder(), out); // fails with ActionExecutionException fail(); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("1 input file(s) do not exist"); + 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 a3853e6540..75d840e31c 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,8 +15,6 @@ package com.google.devtools.build.lib.skyframe; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Function; @@ -121,8 +119,8 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { registerAction(action); buildArtifact(action.getSoleOutput()); - assertTrue(outOneFileOne.getPath().exists()); - assertTrue(outOneFileTwo.getPath().exists()); + assertThat(outOneFileOne.getPath().exists()).isTrue(); + assertThat(outOneFileTwo.getPath().exists()).isTrue(); } /** Simple test for the case with dependencies. */ @@ -138,10 +136,10 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buildArtifact(outTwo); - assertTrue(outOneFileOne.getPath().exists()); - assertTrue(outOneFileTwo.getPath().exists()); - assertTrue(outTwoFileOne.getPath().exists()); - assertTrue(outTwoFileTwo.getPath().exists()); + assertThat(outOneFileOne.getPath().exists()).isTrue(); + assertThat(outOneFileTwo.getPath().exists()).isTrue(); + assertThat(outTwoFileOne.getPath().exists()).isTrue(); + assertThat(outTwoFileTwo.getPath().exists()).isTrue(); } @Test @@ -191,13 +189,13 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buttonOne.pressed = buttonTwo.pressed = false; buildArtifact(outTwo); - assertTrue(buttonOne.pressed); // built - assertTrue(buttonTwo.pressed); // built + assertThat(buttonOne.pressed).isTrue(); // built + assertThat(buttonTwo.pressed).isTrue(); // built buttonOne.pressed = buttonTwo.pressed = false; buildArtifact(outTwo); - assertFalse(buttonOne.pressed); // not built - assertFalse(buttonTwo.pressed); // not built + assertThat(buttonOne.pressed).isFalse(); // not built + assertThat(buttonTwo.pressed).isFalse(); // not built } /** @@ -220,26 +218,26 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buttonOne.pressed = buttonTwo.pressed = false; buildArtifact(outTwo); - assertTrue(buttonOne.pressed); // built - assertTrue(buttonTwo.pressed); // built + assertThat(buttonOne.pressed).isTrue(); // built + assertThat(buttonTwo.pressed).isTrue(); // built buttonOne.pressed = buttonTwo.pressed = false; writeFile(in, "modified_input"); buildArtifact(outTwo); - assertTrue(buttonOne.pressed); // built - assertTrue(buttonTwo.pressed); // not built + assertThat(buttonOne.pressed).isTrue(); // built + assertThat(buttonTwo.pressed).isTrue(); // not built buttonOne.pressed = buttonTwo.pressed = false; writeFile(outOneFileOne, "modified_output"); buildArtifact(outTwo); - assertTrue(buttonOne.pressed); // built - assertFalse(buttonTwo.pressed); // should have been cached + assertThat(buttonOne.pressed).isTrue(); // built + assertThat(buttonTwo.pressed).isFalse(); // should have been cached buttonOne.pressed = buttonTwo.pressed = false; writeFile(outTwoFileOne, "more_modified_output"); buildArtifact(outTwo); - assertFalse(buttonOne.pressed); // not built - assertTrue(buttonTwo.pressed); // built + assertThat(buttonOne.pressed).isFalse(); // not built + assertThat(buttonTwo.pressed).isTrue(); // built } /** Tests that changing a TreeArtifact directory should cause reexeuction. */ @@ -260,8 +258,8 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buttonOne.pressed = buttonTwo.pressed = false; buildArtifact(outTwo); // just a smoke test--if these aren't built we have bigger problems! - assertTrue(buttonOne.pressed); - assertTrue(buttonTwo.pressed); + assertThat(buttonOne.pressed).isTrue(); + assertThat(buttonTwo.pressed).isTrue(); // Adding a file to a directory should cause reexecution. buttonOne.pressed = buttonTwo.pressed = false; @@ -269,32 +267,32 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { touchFile(spuriousOutputOne); buildArtifact(outTwo); // Should re-execute, and delete spurious output - assertFalse(spuriousOutputOne.exists()); - assertTrue(buttonOne.pressed); - assertFalse(buttonTwo.pressed); // should have been cached + assertThat(spuriousOutputOne.exists()).isFalse(); + assertThat(buttonOne.pressed).isTrue(); + assertThat(buttonTwo.pressed).isFalse(); // should have been cached buttonOne.pressed = buttonTwo.pressed = false; Path spuriousOutputTwo = outTwo.getPath().getRelative("anotherSpuriousOutput"); touchFile(spuriousOutputTwo); buildArtifact(outTwo); - assertFalse(spuriousOutputTwo.exists()); - assertFalse(buttonOne.pressed); - assertTrue(buttonTwo.pressed); + assertThat(spuriousOutputTwo.exists()).isFalse(); + assertThat(buttonOne.pressed).isFalse(); + assertThat(buttonTwo.pressed).isTrue(); // Deleting should cause reexecution. buttonOne.pressed = buttonTwo.pressed = false; deleteFile(outOneFileOne); buildArtifact(outTwo); - assertTrue(outOneFileOne.getPath().exists()); - assertTrue(buttonOne.pressed); - assertFalse(buttonTwo.pressed); // should have been cached + assertThat(outOneFileOne.getPath().exists()).isTrue(); + assertThat(buttonOne.pressed).isTrue(); + assertThat(buttonTwo.pressed).isFalse(); // should have been cached buttonOne.pressed = buttonTwo.pressed = false; deleteFile(outTwoFileOne); buildArtifact(outTwo); - assertTrue(outTwoFileOne.getPath().exists()); - assertFalse(buttonOne.pressed); - assertTrue(buttonTwo.pressed); + assertThat(outTwoFileOne.getPath().exists()).isTrue(); + assertThat(buttonOne.pressed).isFalse(); + assertThat(buttonTwo.pressed).isTrue(); } /** TreeArtifacts don't care about mtime, even when the file is empty. */ @@ -318,30 +316,30 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buttonOne.pressed = buttonTwo.pressed = false; buildArtifact(outTwo); - assertTrue(buttonOne.pressed); // built - assertTrue(buttonTwo.pressed); // built + assertThat(buttonOne.pressed).isTrue(); // built + assertThat(buttonTwo.pressed).isTrue(); // built buttonOne.pressed = buttonTwo.pressed = false; touchFile(in); buildArtifact(outTwo); // mtime does not matter. - assertFalse(buttonOne.pressed); - assertFalse(buttonTwo.pressed); + assertThat(buttonOne.pressed).isFalse(); + assertThat(buttonTwo.pressed).isFalse(); // None of the below following should result in anything being built. buttonOne.pressed = buttonTwo.pressed = false; touchFile(outOneFileOne); buildArtifact(outTwo); // Nothing should be built. - assertFalse(buttonOne.pressed); - assertFalse(buttonTwo.pressed); + assertThat(buttonOne.pressed).isFalse(); + assertThat(buttonTwo.pressed).isFalse(); buttonOne.pressed = buttonTwo.pressed = false; touchFile(outOneFileTwo); buildArtifact(outTwo); // Nothing should be built. - assertFalse(buttonOne.pressed); - assertFalse(buttonTwo.pressed); + assertThat(buttonOne.pressed).isFalse(); + assertThat(buttonTwo.pressed).isFalse(); } /** Tests that the declared order of TreeArtifact contents does not matter. */ @@ -455,17 +453,17 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { } private static void checkDirectoryPermissions(Path path) throws IOException { - assertTrue(path.isDirectory()); - assertTrue(path.isExecutable()); - assertTrue(path.isReadable()); - assertFalse(path.isWritable()); + assertThat(path.isDirectory()).isTrue(); + assertThat(path.isExecutable()).isTrue(); + assertThat(path.isReadable()).isTrue(); + assertThat(path.isWritable()).isFalse(); } private static void checkFilePermissions(Path path) throws IOException { - assertFalse(path.isDirectory()); - assertTrue(path.isExecutable()); - assertTrue(path.isReadable()); - assertFalse(path.isWritable()); + assertThat(path.isDirectory()).isFalse(); + assertThat(path.isExecutable()).isTrue(); + assertThat(path.isReadable()).isTrue(); + assertThat(path.isWritable()).isFalse(); } @Test @@ -777,7 +775,7 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buildArtifact(artifact2); fail("Expected BuildFailedException"); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("not all outputs were created or valid"); + assertThat(e).hasMessageThat().contains("not all outputs were created or valid"); } } @@ -822,7 +820,7 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buildArtifact(artifact2); fail("Expected BuildFailedException"); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("Throwing dummy action"); + assertThat(e).hasMessageThat().contains("Throwing dummy action"); } } @@ -866,7 +864,7 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buildArtifact(artifact2); fail("Expected BuildFailedException"); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("Throwing dummy action"); + assertThat(e).hasMessageThat().contains("Throwing dummy action"); } } @@ -890,7 +888,7 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { buildArtifact(artifact2); fail("Expected BuildFailedException"); } catch (BuildFailedException e) { - assertThat(e.getMessage()).contains("Throwing dummy action"); + assertThat(e).hasMessageThat().contains("Throwing dummy action"); } } @@ -999,7 +997,7 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { } Artifact output = getSoleOutput(); - assertTrue(output.getPath().exists()); + assertThat(output.getPath().exists()).isTrue(); try { effect.call(); executeTestBehavior(actionExecutionContext); @@ -1147,8 +1145,8 @@ public class TreeArtifactBuildTest extends TimestampBuilderTestCase { } // both iterators must be of the same size - assertFalse(inputIterator.hasNext()); - assertFalse(inputIterator.hasNext()); + assertThat(inputIterator.hasNext()).isFalse(); + assertThat(inputIterator.hasNext()).isFalse(); } } 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 56bf8a511c..647d90f885 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 @@ -191,7 +191,7 @@ public class TreeArtifactMetadataTest extends ArtifactFunctionTestCase { ImmutableList.of(PathFragment.create("one"))); fail("MissingInputFileException expected, got " + value); } catch (Exception e) { - assertThat(Throwables.getRootCause(e).getMessage()).contains(exception.getMessage()); + assertThat(Throwables.getRootCause(e)).hasMessageThat().contains(exception.getMessage()); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java index 714c662fc8..61a6e9865f 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java @@ -14,9 +14,7 @@ package com.google.devtools.build.lib.skyframe; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; @@ -178,7 +176,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { (PackageValue) externalSkyFunc .compute(ExternalPackageFunction.key(workspacePath), getEnv()); Package pkg = value.getPackage(); - assertTrue(pkg.containsErrors()); + assertThat(pkg.containsErrors()).isTrue(); MoreAsserts.assertContainsEvent(pkg.getEvents(), "foo$ is not a legal workspace name"); } @@ -190,7 +188,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { SkyKey key = ExternalPackageFunction.key(workspacePath); PackageValue value = (PackageValue) externalSkyFunc.compute(key, getEnv()); Package pkg = value.getPackage(); - assertEquals(Label.parseAbsolute("//foo:bar"), getLabelMapping(pkg, "foo/bar")); + assertThat(getLabelMapping(pkg, "foo/bar")).isEqualTo(Label.parseAbsolute("//foo:bar")); MoreAsserts.assertNoEvents(pkg.getEvents()); } @@ -202,7 +200,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { SkyKey key = ExternalPackageFunction.key(workspacePath); PackageValue value = (PackageValue) externalSkyFunc.compute(key, getEnv()); Package pkg = value.getPackage(); - assertEquals(Label.parseAbsolute("//foo:bar"), getLabelMapping(pkg, "foo/bar")); + assertThat(getLabelMapping(pkg, "foo/bar")).isEqualTo(Label.parseAbsolute("//foo:bar")); MoreAsserts.assertNoEvents(pkg.getEvents()); } @@ -216,7 +214,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { (PackageValue) externalSkyFunc .compute(ExternalPackageFunction.key(workspacePath), getEnv()); Package pkg = value.getPackage(); - assertTrue(pkg.containsErrors()); + assertThat(pkg.containsErrors()).isTrue(); MoreAsserts.assertContainsEvent(pkg.getEvents(), "target names may not contain ':'"); } @@ -230,7 +228,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { (PackageValue) externalSkyFunc .compute(ExternalPackageFunction.key(workspacePath), getEnv()); Package pkg = value.getPackage(); - assertTrue(pkg.containsErrors()); + assertThat(pkg.containsErrors()).isTrue(); MoreAsserts.assertContainsEvent(pkg.getEvents(), "target names may not contain ':'"); } @@ -245,7 +243,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { (PackageValue) externalSkyFunc .compute(ExternalPackageFunction.key(workspacePath), getEnv()); Package pkg = value.getPackage(); - assertFalse(pkg.containsErrors()); + assertThat(pkg.containsErrors()).isFalse(); MoreAsserts.assertNoEvents(pkg.getEvents()); } @@ -258,7 +256,7 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { SkyKey key = ExternalPackageFunction.key(workspacePath); PackageValue value = (PackageValue) externalSkyFunc.compute(key, getEnv()); Package pkg = value.getPackage(); - assertEquals(Label.parseAbsolute("//foo:bar"), getLabelMapping(pkg, "foo/bar")); + assertThat(getLabelMapping(pkg, "foo/bar")).isEqualTo(Label.parseAbsolute("//foo:bar")); MoreAsserts.assertNoEvents(pkg.getEvents()); } } |