diff options
author | 2015-03-06 15:58:35 +0000 | |
---|---|---|
committer | 2015-03-10 13:55:19 +0000 | |
commit | 795895aff87cdb0a5a1e8850b17ccf3863547a1c (patch) | |
tree | fced9c8a2124bfcfb8dfe5de3ba89ae6a25065db /src/test/java/com/google/devtools/build/lib/vfs | |
parent | 0bacd7c86ceade660a10193645fc93d68606cffc (diff) |
Some more cleanup.
--
MOS_MIGRATED_REVID=87942730
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/vfs')
13 files changed, 141 insertions, 141 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java index b6e88d8976..9481b229c8 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java @@ -473,7 +473,7 @@ public abstract class FileSystemTest { public void testCreateDirectoryIsOnlyChildInParent() throws Exception { Path newPath = xEmptyDirectory.getChild("new-dir"); newPath.createDirectory(); - assertEquals(1, newPath.getParentDirectory().getDirectoryEntries().size()); + assertThat(newPath.getParentDirectory().getDirectoryEntries()).hasSize(1); assertThat(newPath.getParentDirectory().getDirectoryEntries()).containsExactly(newPath); } @@ -515,7 +515,7 @@ public abstract class FileSystemTest { public void testCreateDirectoriesIsOnlyChildInParent() throws Exception { Path newPath = absolutize("new-dir/sub/directory"); FileSystemUtils.createDirectoryAndParents(newPath); - assertEquals(1, newPath.getParentDirectory().getDirectoryEntries().size()); + assertThat(newPath.getParentDirectory().getDirectoryEntries()).hasSize(1); assertThat(newPath.getParentDirectory().getDirectoryEntries()).containsExactly(newPath); } @@ -531,7 +531,7 @@ public abstract class FileSystemTest { public void testCreateFileIsOnlyChildInParent() throws Exception { Path newPath = xEmptyDirectory.getChild("new-file"); FileSystemUtils.createEmptyFile(newPath); - assertEquals(1, newPath.getParentDirectory().getDirectoryEntries().size()); + assertThat(newPath.getParentDirectory().getDirectoryEntries()).hasSize(1); assertThat(newPath.getParentDirectory().getDirectoryEntries()).containsExactly(newPath); } @@ -548,7 +548,7 @@ public abstract class FileSystemTest { xFile.createDirectory(); fail(); } catch (IOException e) { - assertEquals(xFile + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xFile + " (File exists)"); } } @@ -571,7 +571,7 @@ public abstract class FileSystemTest { xChildOfReadonlyDir.createDirectory(); fail(); } catch (IOException e) { - assertEquals(xChildOfReadonlyDir + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xChildOfReadonlyDir + " (Permission denied)"); } } @@ -594,7 +594,7 @@ public abstract class FileSystemTest { FileSystemUtils.createEmptyFile(xChildOfReadonlyDir); fail(); } catch (IOException e) { - assertEquals(xChildOfReadonlyDir + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xChildOfReadonlyDir + " (Permission denied)"); } } @@ -649,7 +649,7 @@ public abstract class FileSystemTest { if (ex instanceof FileNotFoundException) { fail("The method should throw an object of class IOException."); } - assertEquals(xFile + " (Not a directory)", ex.getMessage()); + assertThat(ex).hasMessage(xFile + " (Not a directory)"); } } @@ -660,7 +660,7 @@ public abstract class FileSystemTest { somePath.getDirectoryEntries(); fail("FileNotFoundException not thrown."); } catch (Exception x) { - assertEquals(somePath + " (No such file or directory)", x.getMessage()); + assertThat(x).hasMessage(somePath + " (No such file or directory)"); } } @@ -734,7 +734,7 @@ public abstract class FileSystemTest { xNonEmptyDirectory.delete(); fail(); } catch (IOException e) { - assertEquals(xNonEmptyDirectory + " (Directory not empty)", e.getMessage()); + assertThat(e).hasMessage(xNonEmptyDirectory + " (Directory not empty)"); } } @@ -835,7 +835,7 @@ public abstract class FileSystemTest { newPath.getLastModifiedTime(); fail("FileNotFoundException not thrown!"); } catch (FileNotFoundException x) { - assertEquals(newPath + " (No such file or directory)", x.getMessage()); + assertThat(x).hasMessage(newPath + " (No such file or directory)"); } } @@ -847,7 +847,7 @@ public abstract class FileSystemTest { newPath.getFileSize(); fail("FileNotFoundException not thrown."); } catch (FileNotFoundException e) { - assertEquals(newPath + " (No such file or directory)", e.getMessage()); + assertThat(e).hasMessage(newPath + " (No such file or directory)"); } } @@ -872,75 +872,75 @@ public abstract class FileSystemTest { @Test public void testInputAndOutputStreamEOF() throws Exception { - OutputStream outStream = xFile.getOutputStream(); - outStream.write(1); - outStream.close(); + try (OutputStream outStream = xFile.getOutputStream()) { + outStream.write(1); + } - InputStream inStream = xFile.getInputStream(); - inStream.read(); + try (InputStream inStream = xFile.getInputStream()) { + inStream.read(); assertEquals(-1, inStream.read()); - inStream.close(); + } } @Test public void testInputAndOutputStream() throws Exception { - OutputStream outStream = xFile.getOutputStream(); - for (int i = 33; i < 126; i++) { - outStream.write(i); + try (OutputStream outStream = xFile.getOutputStream()) { + for (int i = 33; i < 126; i++) { + outStream.write(i); + } } - outStream.close(); - InputStream inStream = xFile.getInputStream(); - for (int i = 33; i < 126; i++) { - int readValue = inStream.read(); - assertEquals(i,readValue); + try (InputStream inStream = xFile.getInputStream()) { + for (int i = 33; i < 126; i++) { + int readValue = inStream.read(); + assertEquals(i, readValue); + } } - inStream.close(); } @Test public void testInputAndOutputStreamAppend() throws Exception { - OutputStream outStream = xFile.getOutputStream(); - for (int i = 33; i < 126; i++) { - outStream.write(i); + try (OutputStream outStream = xFile.getOutputStream()) { + for (int i = 33; i < 126; i++) { + outStream.write(i); + } } - outStream.close(); - OutputStream appendOut = xFile.getOutputStream(true); - for (int i = 126; i < 155; i++) { - appendOut.write(i); + try (OutputStream appendOut = xFile.getOutputStream(true)) { + for (int i = 126; i < 155; i++) { + appendOut.write(i); + } } - appendOut.close(); - InputStream inStream = xFile.getInputStream(); - for (int i = 33; i < 155; i++) { - int readValue = inStream.read(); - assertEquals(i,readValue); + try (InputStream inStream = xFile.getInputStream()) { + for (int i = 33; i < 155; i++) { + int readValue = inStream.read(); + assertEquals(i, readValue); + } } - inStream.close(); } @Test public void testInputAndOutputStreamNoAppend() throws Exception { - OutputStream outStream = xFile.getOutputStream(); - outStream.write(1); - outStream.close(); + try (OutputStream outStream = xFile.getOutputStream()) { + outStream.write(1); + } - OutputStream noAppendOut = xFile.getOutputStream(false); - noAppendOut.close(); + try (OutputStream noAppendOut = xFile.getOutputStream(false)) { + } - InputStream inStream = xFile.getInputStream(); - assertEquals(-1, inStream.read()); - inStream.close(); + try (InputStream inStream = xFile.getInputStream()) { + assertEquals(-1, inStream.read()); + } } @Test public void testGetOutputStreamCreatesFile() throws Exception { Path newFile = absolutize("does_not_exist_yet.txt"); - OutputStream out = newFile.getOutputStream(); - out.write(42); - out.close(); + try (OutputStream out = newFile.getOutputStream()) { + out.write(42); + } assertTrue(newFile.isFile()); } @@ -951,7 +951,7 @@ public abstract class FileSystemTest { xEmptyDirectory.getOutputStream(); fail("The Exception was not thrown!"); } catch (IOException ex) { - assertEquals(xEmptyDirectory + " (Is a directory)", ex.getMessage()); + assertThat(ex).hasMessage(xEmptyDirectory + " (Is a directory)"); } } @@ -961,7 +961,7 @@ public abstract class FileSystemTest { xEmptyDirectory.getInputStream(); fail("The Exception was not thrown!"); } catch (IOException ex) { - assertEquals(xEmptyDirectory + " (Is a directory)", ex.getMessage()); + assertThat(ex).hasMessage(xEmptyDirectory + " (Is a directory)"); } } @@ -987,7 +987,7 @@ public abstract class FileSystemTest { xNonEmptyDirectory.renameTo(xEmptyDirectory); // succeeds assertFalse(xNonEmptyDirectory.exists()); assertTrue(xEmptyDirectory.isDirectory()); - assertFalse(xEmptyDirectory.getDirectoryEntries().isEmpty()); + assertThat(xEmptyDirectory.getDirectoryEntries()).isNotEmpty(); } @Test @@ -1011,8 +1011,8 @@ public abstract class FileSystemTest { assertTrue(xNonEmptyDirectory.isDirectory()); assertTrue(xEmptyDirectory.isDirectory()); - assertTrue(xEmptyDirectory.getDirectoryEntries().isEmpty()); - assertFalse(xNonEmptyDirectory.getDirectoryEntries().isEmpty()); + assertThat(xEmptyDirectory.getDirectoryEntries()).isEmpty(); + assertThat(xNonEmptyDirectory.getDirectoryEntries()).isNotEmpty(); } @Test @@ -1021,7 +1021,7 @@ public abstract class FileSystemTest { xEmptyDirectory.renameTo(xFile); fail(); } catch (IOException e) { - assertEquals(xEmptyDirectory + " -> " + xFile + " (Not a directory)", e.getMessage()); + assertThat(e).hasMessage(xEmptyDirectory + " -> " + xFile + " (Not a directory)"); } } @@ -1044,8 +1044,7 @@ public abstract class FileSystemTest { xFile.renameTo(xEmptyDirectory); fail(); } catch (IOException e) { - assertEquals(xFile + " -> " + xEmptyDirectory + " (Is a directory)", - e.getMessage()); + assertThat(e).hasMessage(xFile + " -> " + xEmptyDirectory + " (Is a directory)"); } } @@ -1081,7 +1080,7 @@ public abstract class FileSystemTest { testFS.getPath("not-absolute"); fail("The expected Exception was not thrown."); } catch (IllegalArgumentException ex) { - assertEquals("not-absolute (not an absolute path)", ex.getMessage()); + assertThat(ex).hasMessage("not-absolute (not an absolute path)"); } } @@ -1091,7 +1090,7 @@ public abstract class FileSystemTest { testFS.getPath(new PathFragment("not-absolute")); fail("The expected Exception was not thrown."); } catch (IllegalArgumentException ex) { - assertEquals("not-absolute (not an absolute path)", ex.getMessage()); + assertThat(ex).hasMessage("not-absolute (not an absolute path)"); } } @@ -1127,7 +1126,7 @@ public abstract class FileSystemTest { xNothing.isExecutable(); fail("No exception thrown."); } catch (FileNotFoundException ex) { - assertEquals(xNothing + " (No such file or directory)", ex.getMessage()); + assertThat(ex).hasMessage(xNothing + " (No such file or directory)"); } } @@ -1137,7 +1136,7 @@ public abstract class FileSystemTest { xNothing.setExecutable(true); fail("No exception thrown."); } catch (FileNotFoundException ex) { - assertEquals(xNothing + " (No such file or directory)", ex.getMessage()); + assertThat(ex).hasMessage(xNothing + " (No such file or directory)"); } } @@ -1147,7 +1146,7 @@ public abstract class FileSystemTest { xNothing.isWritable(); fail("No exception thrown."); } catch (FileNotFoundException ex) { - assertEquals(xNothing + " (No such file or directory)", ex.getMessage()); + assertThat(ex).hasMessage(xNothing + " (No such file or directory)"); } } @@ -1157,7 +1156,7 @@ public abstract class FileSystemTest { xNothing.setWritable(false); fail("No exception thrown."); } catch (FileNotFoundException ex) { - assertEquals(xNothing + " (No such file or directory)", ex.getMessage()); + assertThat(ex).hasMessage(xNothing + " (No such file or directory)"); } } @@ -1205,7 +1204,7 @@ public abstract class FileSystemTest { FileSystemUtils.writeContent(xFile, "hello, world!".getBytes()); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xFile + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xFile + " (Permission denied)"); } } @@ -1217,7 +1216,7 @@ public abstract class FileSystemTest { FileSystemUtils.readContent(xFile); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xFile + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xFile + " (Permission denied)"); } } @@ -1230,7 +1229,7 @@ public abstract class FileSystemTest { FileSystemUtils.createEmptyFile(xNonEmptyDirectoryBar); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xNonEmptyDirectoryBar + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xNonEmptyDirectoryBar + " (Permission denied)"); } } @@ -1243,7 +1242,7 @@ public abstract class FileSystemTest { xNonEmptyDirectoryBar.createDirectory(); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xNonEmptyDirectoryBar + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xNonEmptyDirectoryBar + " (Permission denied)"); } } @@ -1280,7 +1279,7 @@ public abstract class FileSystemTest { xNonEmptyDirectoryFoo.delete(); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xNonEmptyDirectoryFoo + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xNonEmptyDirectoryFoo + " (Permission denied)"); } } @@ -1294,7 +1293,7 @@ public abstract class FileSystemTest { createSymbolicLink(xNonEmptyDirectoryBar, xNonEmptyDirectoryFoo); fail("No exception thrown."); } catch (IOException e) { - assertEquals(xNonEmptyDirectoryBar + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xNonEmptyDirectoryBar + " (Permission denied)"); } } } @@ -1348,7 +1347,7 @@ public abstract class FileSystemTest { @Test public void testResolveNonSymlinks() throws Exception { if (supportsSymlinks) { - assertEquals(null, testFS.resolveOneLink(xFile)); + assertNull(testFS.resolveOneLink(xFile)); assertEquals(xFile, xFile.resolveSymbolicLinks()); } } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java index 21ca39b8f0..11c90c52a6 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java @@ -131,7 +131,7 @@ public class FileSystemUtilsTest { assertTrue(copiedADir.exists()); assertTrue(copiedADir.isDirectory()); Collection<Path> aDirEntries = copiedADir.getDirectoryEntries(); - assertEquals(2, aDirEntries.size()); + assertThat(aDirEntries).hasSize(2); Path copiedFile3 = copiedADir.getChild("file-3"); assertTrue(copiedFile3.exists()); @@ -243,7 +243,7 @@ public class FileSystemUtilsTest { assertPath("/foo.baz", FileSystemUtils.replaceExtension(fileSystem.getPath("/foo"), ".baz")); assertPath("/foo.baz", FileSystemUtils.replaceExtension(fileSystem.getPath("/foo.cc"), ".baz")); assertPath("/.baz", FileSystemUtils.replaceExtension(fileSystem.getPath("/.cc"), ".baz")); - assertEquals(null, FileSystemUtils.replaceExtension(fileSystem.getPath("/"), ".baz")); + assertNull(FileSystemUtils.replaceExtension(fileSystem.getPath("/"), ".baz")); } @Test @@ -267,14 +267,14 @@ public class FileSystemUtilsTest { assertPath("/foo.baz", FileSystemUtils.replaceExtension(new PathFragment("/foo.cc"), ".baz")); assertPath(".baz", FileSystemUtils.replaceExtension(new PathFragment(".cc"), ".baz")); - assertEquals(null, FileSystemUtils.replaceExtension(new PathFragment("/"), ".baz")); - assertEquals(null, FileSystemUtils.replaceExtension(new PathFragment(""), ".baz")); + assertNull(FileSystemUtils.replaceExtension(new PathFragment("/"), ".baz")); + assertNull(FileSystemUtils.replaceExtension(new PathFragment(""), ".baz")); assertPath("foo/bar.baz", FileSystemUtils.replaceExtension(new PathFragment("foo/bar.pony"), ".baz", ".pony")); assertPath("foo/bar.baz", FileSystemUtils.replaceExtension(new PathFragment("foo/bar"), ".baz", "")); - assertEquals(null, FileSystemUtils.replaceExtension(new PathFragment(""), ".baz", ".pony")); - assertEquals(null, + assertNull(FileSystemUtils.replaceExtension(new PathFragment(""), ".baz", ".pony")); + assertNull( FileSystemUtils.replaceExtension(new PathFragment("foo/bar.pony"), ".baz", ".unicorn")); } @@ -294,8 +294,8 @@ public class FileSystemUtilsTest { appendWithoutExtension(new PathFragment("libfoo.jar/"), "-src")); assertPath("libfoo.src.jar", appendWithoutExtension(new PathFragment("libfoo.jar"), ".src")); - assertEquals(null, appendWithoutExtension(new PathFragment("/"), "-src")); - assertEquals(null, appendWithoutExtension(new PathFragment(""), "-src")); + assertNull(appendWithoutExtension(new PathFragment("/"), "-src")); + assertNull(appendWithoutExtension(new PathFragment(""), "-src")); } @Test @@ -357,7 +357,7 @@ public class FileSystemUtilsTest { testFile.setLastModifiedTime(42); touchFile(testFile); - assertTrue(testFile.getLastModifiedTime() >= oldTime); + assertThat(testFile.getLastModifiedTime()).isAtLeast(oldTime); } @Test @@ -439,9 +439,8 @@ public class FileSystemUtilsTest { copyFile(originalFile, aDir); fail(); } catch (IOException ex) { - assertEquals("error copying file: couldn't delete destination: " - + aDir + " (Directory not empty)", - ex.getMessage()); + assertThat(ex).hasMessage( + "error copying file: couldn't delete destination: " + aDir + " (Directory not empty)"); } } @@ -488,7 +487,7 @@ public class FileSystemUtilsTest { FileSystemUtils.copyTreesBelow(topDir, aDir); fail("Should not be able to copy a directory to a subdir"); } catch (IllegalArgumentException expected) { - assertEquals("/top-dir/a-dir is a subdirectory of /top-dir", expected.getMessage()); + assertThat(expected).hasMessage("/top-dir/a-dir is a subdirectory of /top-dir"); } } @@ -499,7 +498,7 @@ public class FileSystemUtilsTest { FileSystemUtils.copyTreesBelow(file1, aDir); fail("Should not be able to copy a file with copyDirectory method"); } catch (IOException expected) { - assertEquals("/top-dir/file-1 (Not a directory)", expected.getMessage()); + assertThat(expected).hasMessage("/top-dir/file-1 (Not a directory)"); } } @@ -513,7 +512,7 @@ public class FileSystemUtilsTest { FileSystemUtils.copyTreesBelow(copyDir, file4); fail("Should not be able to copy a directory to a file"); } catch (IOException expected) { - assertEquals("/file-4 (Not a directory)", expected.getMessage()); + assertThat(expected).hasMessage("/file-4 (Not a directory)"); } } @@ -526,7 +525,7 @@ public class FileSystemUtilsTest { FileSystemUtils.copyTreesBelow(unexistingDir, aDir); fail("Should not be able to copy from an unexisting path"); } catch (FileNotFoundException expected) { - assertEquals("/unexisting-dir (No such file or directory)", expected.getMessage()); + assertThat(expected).hasMessage("/unexisting-dir (No such file or directory)"); } } @@ -661,7 +660,7 @@ public class FileSystemUtilsTest { createDirectoryAndParents(theHierarchy); fail(); } catch (IOException e) { - assertEquals("/somewhere/deep/in (Not a directory)", e.getMessage()); + assertThat(e).hasMessage("/somewhere/deep/in (Not a directory)"); } } @@ -873,6 +872,6 @@ public class FileSystemUtilsTest { clock.advanceMillis(1000); FileSystemUtils.ensureSymbolicLink(file, target); long timestamp = file.getLastModifiedTime(Symlinks.NOFOLLOW); - assertTrue(timestamp == prevTimeMillis); + assertEquals(prevTimeMillis, timestamp); } } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java index 37b7dc4957..a751e1becc 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.vfs; 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; @@ -138,7 +137,7 @@ public class GlobTest { Collection<Path> globResult = UnixGlob.forPath(fs.getPath("/does/not/exist")) .addPattern("*.txt") .globInterruptible(); - assertEquals(0, globResult.size()); + assertThat(globResult).isEmpty(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java index 9ab9bfa9f3..53dd7a2fed 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +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.assertNull; @@ -260,8 +261,8 @@ public class PathFragmentTest { assertEquals("foo", new PathFragment("/foo/").getBaseName()); assertEquals("foo", new PathFragment("foo").getBaseName()); assertEquals("foo", new PathFragment("/foo").getBaseName()); - assertEquals("", new PathFragment("/").getBaseName()); - assertEquals("", new PathFragment("").getBaseName()); + assertThat(new PathFragment("/").getBaseName()).isEmpty(); + assertThat(new PathFragment("").getBaseName()).isEmpty(); } private static void assertPath(String expected, PathFragment actual) { @@ -277,10 +278,10 @@ public class PathFragmentTest { assertPath("/baz", new PathFragment("/foo/").replaceName("baz")); assertPath("baz", new PathFragment("foo").replaceName("baz")); assertPath("/baz", new PathFragment("/foo").replaceName("baz")); - assertEquals(null, new PathFragment("/").replaceName("baz")); - assertEquals(null, new PathFragment("/").replaceName("")); - assertEquals(null, new PathFragment("").replaceName("baz")); - assertEquals(null, new PathFragment("").replaceName("")); + assertNull(new PathFragment("/").replaceName("baz")); + assertNull(new PathFragment("/").replaceName("")); + assertNull(new PathFragment("").replaceName("baz")); + assertNull(new PathFragment("").replaceName("")); assertPath("foo/bar/baz", new PathFragment("foo/bar").replaceName("bar/baz")); assertPath("foo/bar/baz", new PathFragment("foo/bar").replaceName("bar/baz/")); diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java index 43c94d4b8f..1e8ceaf876 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +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.assertNull; @@ -167,7 +168,7 @@ public class PathFragmentWindowsTest { assertEquals("bar", new PathFragment("C:/foo/bar").getBaseName()); assertEquals("foo", new PathFragment("C:/foo").getBaseName()); // Never return the drive name as a basename. - assertEquals("", new PathFragment("C:/").getBaseName()); + assertThat(new PathFragment("C:/").getBaseName()).isEmpty(); } private static void assertPath(String expected, PathFragment actual) { @@ -177,7 +178,7 @@ public class PathFragmentWindowsTest { @Test public void testReplaceNameWindows() throws Exception { assertPath("C:/foo/baz", new PathFragment("C:/foo/bar").replaceName("baz")); - assertEquals(null, new PathFragment("C:/").replaceName("baz")); + assertNull(new PathFragment("C:/").replaceName("baz")); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java b/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java index 5e0012ac08..19b2210bae 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.vfs; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.testutil.MoreAsserts.assertSameContents; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -117,7 +116,7 @@ public class RecursiveGlobTest { Collection<Path> globResult = UnixGlob.forPath(fileSystem.getPath("/does/not/exist")) .addPattern("**") .globInterruptible(); - assertEquals(0, globResult.size()); + assertThat(globResult).isEmpty(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java index 6c8071f075..d959fc1f0d 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; @@ -124,8 +125,8 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste public void setUp() throws Exception { super.setUp(); - Preconditions.checkState(testFS instanceof ScopeEscapableFileSystem, - "Not ScopeEscapable: " + testFS); + Preconditions.checkState( + testFS instanceof ScopeEscapableFileSystem, "Not ScopeEscapable: %s", testFS); ((ScopeEscapableFileSystem) testFS).enableScopeChecking(false); for (int i = 1; i <= SCOPE_ROOT.segmentCount(); i++) { testFS.getPath(SCOPE_ROOT.subFragment(0, i)).createDirectory(); @@ -154,7 +155,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste // Checks that the semi-resolved path passed to the delegator matches the expected value. private void checkPath(TestDelegator delegator, PathFragment expectedDelegatedPath) { - assertTrue(expectedDelegatedPath.equals(delegator.lastPath())); + assertEquals(delegator.lastPath(), expectedDelegatedPath); } // Asserts that the condition is false and checks that the expected path was delegated. @@ -300,7 +301,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste // We shouldn't follow final-segment links, so they should never invoke the delegator. delegator.setState(false); assertTrue(fileLink.isSymbolicLink()); - assertTrue(delegator.lastPath() == null); + assertNull(delegator.lastPath()); assertFalseWithPathCheck(dirLink.getRelative("a").isSymbolicLink(), delegator, dirLinkTarget.getRelative("a")); @@ -379,7 +380,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste delegator.setState(false); assertTrue(fileLink.delete()); - assertTrue(delegator.lastPath() == null); // Deleting a link shouldn't require delegation. + assertNull(delegator.lastPath()); // Deleting a link shouldn't require delegation. assertFalseWithPathCheck(dirLink.getRelative("a").delete(), delegator, dirLinkTarget.getRelative("a")); @@ -560,8 +561,8 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste // Renaming a link should work fine. delegator.setState(null); fileLink.renameTo(testFS.getPath(SCOPE_ROOT).getRelative("newname")); - assertEquals(null, delegator.lastPath()); // Renaming a link shouldn't require delegation. - assertEquals(null, delegator.objectState()); + assertNull(delegator.lastPath()); // Renaming a link shouldn't require delegation. + assertNull(delegator.objectState()); // Renaming an out-of-scope path to an in-scope path should fail due to filesystem mismatch // errors. @@ -611,7 +612,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste // Since we're not following the link, this shouldn't invoke delegation. delegator.setState(new PathFragment("whatever")); PathFragment p = fileLink.readSymbolicLink(); - assertEquals(null, delegator.lastPath()); + assertNull(delegator.lastPath()); assertNotSame(delegator.objectState(), p); // This should. @@ -677,7 +678,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste delegator.setState(testFS.getPath("/anything")); Collection<Path> entries = dirLink.getDirectoryEntries(); assertEquals(dirLinkTarget, delegator.lastPath()); - assertEquals(1, entries.size()); + assertThat(entries).hasSize(1); assertSame(delegator.objectState(), entries.iterator().next()); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java index a728c88796..e48a5dd010 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java @@ -92,8 +92,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { assertEquals(newPath.toString().length(), linkPath.getFileSize(Symlinks.NOFOLLOW)); assertEquals(newPath.getFileSize(Symlinks.NOFOLLOW), linkPath.getFileSize()); } - assertEquals(2, - linkPath.getParentDirectory().getDirectoryEntries().size()); + assertThat(linkPath.getParentDirectory().getDirectoryEntries()).hasSize(2); assertThat(linkPath.getParentDirectory().getDirectoryEntries()).containsExactly(newPath, linkPath); } @@ -110,8 +109,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { assertTrue(linkPath.isSymbolicLink()); assertFalse(linkPath.isFile()); assertTrue(linkPath.isDirectory()); - assertEquals(2, - linkPath.getParentDirectory().getDirectoryEntries().size()); + assertThat(linkPath.getParentDirectory().getDirectoryEntries()).hasSize(2); assertThat(linkPath.getParentDirectory(). getDirectoryEntries()).containsExactly(newPath, linkPath); } @@ -168,7 +166,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { xDanglingLink.createDirectory(); fail(); } catch (IOException e) { - assertEquals(xDanglingLink + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xDanglingLink + " (File exists)"); } assertTrue(xDanglingLink.isSymbolicLink()); // still a symbolic link assertFalse(xDanglingLink.isDirectory(Symlinks.FOLLOW)); // link still dangles @@ -180,7 +178,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { xLinkToDirectory.createDirectory(); fail(); } catch (IOException e) { - assertEquals(xLinkToDirectory + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xLinkToDirectory + " (File exists)"); } assertTrue(xLinkToDirectory.isSymbolicLink()); // still a symbolic link assertTrue(xLinkToDirectory.isDirectory(Symlinks.FOLLOW)); // link still points to dir @@ -262,8 +260,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { link.resolveSymbolicLinks(); fail(); } catch (IOException e) { - assertEquals(link + " (Too many levels of symbolic links)", - e.getMessage()); + assertThat(e).hasMessage(link + " (Too many levels of symbolic links)"); } } } @@ -280,7 +277,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { link1.resolveSymbolicLinks(); fail(); } catch (IOException e) { - assertEquals(link1 + " (Too many levels of symbolic links)", e.getMessage()); + assertThat(e).hasMessage(link1 + " (Too many levels of symbolic links)"); } } } @@ -292,7 +289,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { xDanglingLink.resolveSymbolicLinks(); fail(); } catch (IOException e) { - assertEquals(xNothing + " (No such file or directory)", e.getMessage()); + assertThat(e).hasMessage(xNothing + " (No such file or directory)"); } } } @@ -349,14 +346,14 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { xFile.readSymbolicLink(); // not a link fail(); } catch (NotASymlinkException e) { - assertEquals(xFile.toString(), e.getMessage()); + assertThat(e).hasMessage(xFile.toString()); } try { xNothing.readSymbolicLink(); // nothing there fail(); } catch (IOException e) { - assertEquals(xNothing + " (No such file or directory)", e.getMessage()); + assertThat(e).hasMessage(xNothing + " (No such file or directory)"); } } @@ -370,7 +367,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { xChildOfReadonlyDir.createSymbolicLink(xNothing); fail(); } catch (IOException e) { - assertEquals(xChildOfReadonlyDir + " (Permission denied)", e.getMessage()); + assertThat(e).hasMessage(xChildOfReadonlyDir + " (Permission denied)"); } } } @@ -391,8 +388,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { try { someLink.resolveSymbolicLinks(); } catch (FileNotFoundException e) { - assertEquals(newPath.getParentDirectory() - + " (No such file or directory)", e.getMessage()); + assertThat(e).hasMessage(newPath.getParentDirectory() + " (No such file or directory)"); } } } @@ -422,7 +418,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { createSymbolicLink(xEmptyDirectory, xFile); fail(); } catch (IOException e) { // => couldn't be created - assertEquals(xEmptyDirectory + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xEmptyDirectory + " (File exists)"); } assertTrue(xEmptyDirectory.isDirectory(Symlinks.NOFOLLOW)); } @@ -433,7 +429,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { createSymbolicLink(xFile, xEmptyDirectory); fail(); } catch (IOException e) { // => couldn't be created - assertEquals(xFile + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xFile + " (File exists)"); } assertTrue(xFile.isFile(Symlinks.NOFOLLOW)); } @@ -444,7 +440,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { createSymbolicLink(xDanglingLink, xFile); fail(); } catch (IOException e) { - assertEquals(xDanglingLink + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xDanglingLink + " (File exists)"); } assertTrue(xDanglingLink.isSymbolicLink()); // still a symbolic link assertFalse(xDanglingLink.isDirectory()); // link still dangles @@ -456,7 +452,7 @@ public abstract class SymlinkAwareFileSystemTest extends FileSystemTest { createSymbolicLink(xLinkToDirectory, xNothing); fail(); } catch (IOException e) { - assertEquals(xLinkToDirectory + " (File exists)", e.getMessage()); + assertThat(e).hasMessage(xLinkToDirectory + " (File exists)"); } assertTrue(xLinkToDirectory.isSymbolicLink()); // still a symbolic link assertTrue(xLinkToDirectory.isDirectory()); // link still points to dir diff --git a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathEqualityTest.java b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathEqualityTest.java index f5f58e2c7e..a613dc9142 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathEqualityTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathEqualityTest.java @@ -19,6 +19,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.common.testing.EqualsTester; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,9 +44,8 @@ public class UnixPathEqualityTest { } private void assertTwoWayEquals(Object obj1, Object obj2) { - assertTrue(obj1.equals(obj2)); - assertTrue(obj2.equals(obj1)); - assertEquals(obj1.hashCode(), obj2.hashCode()); + assertEquals(obj2, obj1); + new EqualsTester().addEqualityGroup(obj1, obj2).testEquals(); } private void assertTwoWayNotEquals(Object obj1, Object obj2) { diff --git a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathGetParentTest.java b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathGetParentTest.java index 0f679c3e78..dccc6e6a35 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathGetParentTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathGetParentTest.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.vfs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.vfs.util.FileSystems; @@ -53,7 +54,7 @@ public class UnixPathGetParentTest { @Test public void testAbsoluteRootHasNoParent() { - assertEquals(null, getParent("/")); + assertNull(getParent("/")); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathTest.java b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathTest.java index b59336725a..9e4bce3bd8 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/UnixPathTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/UnixPathTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.Lists; +import com.google.common.testing.EqualsTester; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.vfs.util.FileSystems; @@ -156,7 +157,7 @@ public class UnixPathTest { Collection<Path> textFiles = UnixGlob.forPath(unixFs.getPath(tmpDir.getPath())) .addPattern("*/*.txt") .globInterruptible(); - assertEquals(1, textFiles.size()); + assertThat(textFiles).hasSize(1); Path onlyFile = textFiles.iterator().next(); assertEquals(unixFs.getPath(anotherFile.getPath()), onlyFile); @@ -189,8 +190,7 @@ public class UnixPathTest { Path differentPath = unixFs.getPath("/foo/bar/baz"); Object differentType = new Object(); - assertEquals(path.hashCode(), equalPath.hashCode()); - assertEquals(path, equalPath); + new EqualsTester().addEqualityGroup(path, equalPath).testEquals(); assertFalse(path.equals(differentPath)); assertFalse(path.equals(differentType)); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/ZipFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/ZipFileSystemTest.java index 9dc12764ae..3e15524c39 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/ZipFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/ZipFileSystemTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +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; @@ -175,7 +176,7 @@ public class ZipFileSystemTest { throws Exception { InputStream is = fs.getPath(name).getInputStream(); List<String> lines = CharStreams.readLines(new InputStreamReader(is, "ISO-8859-1")); - assertEquals(expectedSize, lines.size()); + assertThat(lines).hasSize(expectedSize); for (int i = 0; i < expectedSize; i++) { assertEquals("body", lines.get(i)); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java index 65ea6f6557..c4b5ccc943 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java @@ -13,8 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.vfs.inmemoryfs; +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.assertNull; import static org.junit.Assert.assertTrue; import com.google.common.collect.Lists; @@ -162,7 +164,7 @@ public class InMemoryFileSystemTest extends ScopeEscapableFileSystemTest { BufferedReader reader = new BufferedReader( new InputStreamReader(file.getInputStream(), Charset.defaultCharset())); assertEquals(TEST_FILE_DATA, reader.readLine()); - assertEquals(null, reader.readLine()); + assertNull(reader.readLine()); Path symlink = base.getRelative("symlink" + i); assertTrue(symlink.exists()); @@ -246,7 +248,7 @@ public class InMemoryFileSystemTest extends ScopeEscapableFileSystemTest { BufferedReader reader = new BufferedReader( new InputStreamReader(file.getInputStream(), Charset.defaultCharset())); assertEquals(TEST_FILE_DATA, reader.readLine()); - assertEquals(null, reader.readLine()); + assertNull(reader.readLine()); } Path symlink = base.getRelative("symlink_" + threadId + "_" + i); @@ -397,7 +399,7 @@ public class InMemoryFileSystemTest extends ScopeEscapableFileSystemTest { try { a.stat(); } catch (IOException e) { - assertEquals("/a (Too many levels of symbolic links)", e.getMessage()); + assertThat(e).hasMessage("/a (Too many levels of symbolic links)"); } } @@ -408,7 +410,7 @@ public class InMemoryFileSystemTest extends ScopeEscapableFileSystemTest { try { a.stat(); } catch (IOException e) { - assertEquals("/a (Too many levels of symbolic links)", e.getMessage()); + assertThat(e).hasMessage("/a (Too many levels of symbolic links)"); } } } |