diff options
author | lberki <lberki@google.com> | 2017-05-30 12:35:33 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-05-30 12:51:57 +0200 |
commit | aea56b36af994b269800602e36000c293cabd00b (patch) | |
tree | 794f6b3b2528353cc39bd383730d408d4ff25233 /src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java | |
parent | 229f393bf460700594ae032a551879e026bd0b91 (diff) |
Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java index b7bb9d1ae8..296703eef6 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java @@ -13,12 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.actions; - import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -68,12 +63,9 @@ public class ArtifactTest { public void testEquivalenceRelation() throws Exception { PathFragment aPath = PathFragment.create("src/a"); PathFragment bPath = PathFragment.create("src/b"); - assertEquals(new Artifact(aPath, rootDir), - new Artifact(aPath, rootDir)); - assertEquals(new Artifact(bPath, rootDir), - new Artifact(bPath, rootDir)); - assertFalse(new Artifact(aPath, rootDir).equals( - new Artifact(bPath, rootDir))); + assertThat(new Artifact(aPath, rootDir)).isEqualTo(new Artifact(aPath, rootDir)); + assertThat(new Artifact(bPath, rootDir)).isEqualTo(new Artifact(bPath, rootDir)); + assertThat(new Artifact(aPath, rootDir).equals(new Artifact(bPath, rootDir))).isFalse(); } @Test @@ -88,24 +80,24 @@ public class ArtifactTest { PathFragment bPath = PathFragment.create("src/b"); Artifact aArtifact = new Artifact(aPath, rootDir); Artifact bArtifact = new Artifact(bPath, rootDir); - assertEquals(-1, Artifact.EXEC_PATH_COMPARATOR.compare(aArtifact, bArtifact)); - assertEquals(0, Artifact.EXEC_PATH_COMPARATOR.compare(aArtifact, aArtifact)); - assertEquals(0, Artifact.EXEC_PATH_COMPARATOR.compare(bArtifact, bArtifact)); - assertEquals(1, Artifact.EXEC_PATH_COMPARATOR.compare(bArtifact, aArtifact)); + assertThat(Artifact.EXEC_PATH_COMPARATOR.compare(aArtifact, bArtifact)).isEqualTo(-1); + assertThat(Artifact.EXEC_PATH_COMPARATOR.compare(aArtifact, aArtifact)).isEqualTo(0); + assertThat(Artifact.EXEC_PATH_COMPARATOR.compare(bArtifact, bArtifact)).isEqualTo(0); + assertThat(Artifact.EXEC_PATH_COMPARATOR.compare(bArtifact, aArtifact)).isEqualTo(1); } @Test public void testRootPrefixedExecPath_normal() throws IOException { Path f1 = scratch.file("/exec/root/dir/file.ext"); Artifact a1 = new Artifact(f1, rootDir, f1.relativeTo(execDir)); - assertEquals("root:dir/file.ext", Artifact.asRootPrefixedExecPath(a1)); + assertThat(Artifact.asRootPrefixedExecPath(a1)).isEqualTo("root:dir/file.ext"); } @Test public void testRootPrefixedExecPath_noRoot() throws IOException { Path f1 = scratch.file("/exec/dir/file.ext"); Artifact a1 = new Artifact(f1.relativeTo(execDir), Root.asDerivedRoot(execDir)); - assertEquals(":dir/file.ext", Artifact.asRootPrefixedExecPath(a1)); + assertThat(Artifact.asRootPrefixedExecPath(a1)).isEqualTo(":dir/file.ext"); } @Test @@ -140,10 +132,10 @@ public class ArtifactTest { Artifact generatedHeader = new Artifact(scratch.file("/foo/bar.proto.h"), root); Artifact generatedCc = new Artifact(scratch.file("/foo/bar.proto.cc"), root); Artifact aCPlusPlusFile = new Artifact(scratch.file("/foo/bar.cc"), root); - assertTrue(JavaSemantics.JAVA_SOURCE.matches(javaFile.getFilename())); - assertTrue(CppFileTypes.CPP_HEADER.matches(generatedHeader.getFilename())); - assertTrue(CppFileTypes.CPP_SOURCE.matches(generatedCc.getFilename())); - assertTrue(CppFileTypes.CPP_SOURCE.matches(aCPlusPlusFile.getFilename())); + assertThat(JavaSemantics.JAVA_SOURCE.matches(javaFile.getFilename())).isTrue(); + assertThat(CppFileTypes.CPP_HEADER.matches(generatedHeader.getFilename())).isTrue(); + assertThat(CppFileTypes.CPP_SOURCE.matches(generatedCc.getFilename())).isTrue(); + assertThat(CppFileTypes.CPP_SOURCE.matches(aCPlusPlusFile.getFilename())).isTrue(); } @Test @@ -156,7 +148,7 @@ public class ArtifactTest { @Test public void testMangledPath() { String path = "dir/sub_dir/name:end"; - assertEquals("dir_Ssub_Udir_Sname_Cend", Actions.escapedPath(path)); + assertThat(Actions.escapedPath(path)).isEqualTo("dir_Ssub_Udir_Sname_Cend"); } private List<Artifact> getFooBarArtifacts(MutableActionGraph actionGraph, boolean collapsedList) @@ -179,7 +171,7 @@ public class ArtifactTest { List<String> paths = new ArrayList<>(); MutableActionGraph actionGraph = new MapBasedActionGraph(); Artifact.addExecPaths(getFooBarArtifacts(actionGraph, false), paths); - assertThat(paths).containsExactlyElementsIn(ImmutableList.of("bar1.h", "bar2.h")); + assertThat(paths).containsExactly("bar1.h", "bar2.h"); } @Test @@ -229,7 +221,7 @@ public class ArtifactTest { List<String> paths = new ArrayList<>(); MutableActionGraph actionGraph = new MapBasedActionGraph(); Artifact.addExecPaths(getFooBarArtifacts(actionGraph, false), paths); - assertThat(paths).containsExactlyElementsIn(ImmutableList.of("bar1.h", "bar2.h")); + assertThat(paths).containsExactly("bar1.h", "bar2.h"); } @Test @@ -279,14 +271,14 @@ public class ArtifactTest { public void testRootRelativePathIsSameAsExecPath() throws Exception { Root root = Root.asSourceRoot(scratch.dir("/foo")); Artifact a = new Artifact(scratch.file("/foo/bar1.h"), root); - assertSame(a.getExecPath(), a.getRootRelativePath()); + assertThat(a.getRootRelativePath()).isSameAs(a.getExecPath()); } @Test public void testToDetailString() throws Exception { Artifact a = new Artifact(scratch.file("/a/b/c"), Root.asDerivedRoot(scratch.dir("/a/b")), PathFragment.create("b/c")); - assertEquals("[[/a]b]c", a.toDetailString()); + assertThat(a.toDetailString()).isEqualTo("[[/a]b]c"); } @Test @@ -303,9 +295,10 @@ public class ArtifactTest { @Test public void testSerializeToString() throws Exception { - assertEquals("b/c /3", - new Artifact(scratch.file("/a/b/c"), - Root.asDerivedRoot(scratch.dir("/a"))).serializeToString()); + assertThat( + new Artifact(scratch.file("/a/b/c"), Root.asDerivedRoot(scratch.dir("/a"))) + .serializeToString()) + .isEqualTo("b/c /3"); } @Test @@ -314,15 +307,19 @@ public class ArtifactTest { Root root = Root.asDerivedRoot(scratch.dir("/aaa/bbb")); PathFragment execPath = PathFragment.create("bbb/ccc"); - assertEquals("bbb/ccc /3", new Artifact(path, root, execPath).serializeToString()); + assertThat(new Artifact(path, root, execPath).serializeToString()).isEqualTo("bbb/ccc /3"); } @Test public void testSerializeToStringWithOwner() throws Exception { - assertEquals("b/c /3 //foo:bar", - new Artifact(scratch.file("/aa/b/c"), Root.asDerivedRoot(scratch.dir("/aa")), - PathFragment.create("b/c"), - new LabelArtifactOwner(Label.parseAbsoluteUnchecked("//foo:bar"))).serializeToString()); + assertThat( + new Artifact( + scratch.file("/aa/b/c"), + Root.asDerivedRoot(scratch.dir("/aa")), + PathFragment.create("b/c"), + new LabelArtifactOwner(Label.parseAbsoluteUnchecked("//foo:bar"))) + .serializeToString()) + .isEqualTo("b/c /3 //foo:bar"); } @Test |