diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java index e128ffb6ef73..fbd3241fec23 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilLightTest.java @@ -12,7 +12,6 @@ import org.junit.Rule; import org.junit.Test; import java.io.File; -import java.io.IOException; import static com.intellij.mock.MockVirtualFile.dir; import static com.intellij.mock.MockVirtualFile.file; @@ -63,7 +62,7 @@ public class VfsUtilLightTest extends BareTestFixtureTestCase { } @Test - public void testGetPathForVFileCreateEventForJarReturnsNormalizedPathSeparators() throws IOException { + public void testGetPathForVFileCreateEventForJarReturnsNormalizedPathSeparators() { File jarFile = IoTestUtil.createTestJar(tempDir.newFile("test.jar")); assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jarFile)); VirtualFile jarRoot = VirtualFileManager.getInstance().findFileByUrl("jar://" + FileUtil.toSystemIndependentName(jarFile.getPath()) + "!/"); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java index 0ebbf65c029d..2fec3c30d9e5 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java @@ -85,7 +85,7 @@ public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { } @Test - public void testFindRootPerformance() throws IOException { + public void testFindRootPerformance() { File tempJar = IoTestUtil.createTestJar(myTempDir.newFile("test.jar")); VirtualFile jar = LocalFileSystem.getInstance().findFileByIoFile(tempJar); assertNotNull(jar); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java index f9a406db6bc7..9da31e7eb44e 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java @@ -100,7 +100,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase { } @Test - public void testFindChildWithTrailingSpace() throws IOException { + public void testFindChildWithTrailingSpace() { File tempDir = myTempDir.newDirectory(); VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); assertNotNull(vDir); @@ -207,7 +207,7 @@ public class VfsUtilTest extends BareTestFixtureTestCase { } @Test - public void testFindRootWithDenormalizedPath() throws IOException { + public void testFindRootWithDenormalizedPath() { File tempJar = IoTestUtil.createTestJar(myTempDir.newFile("test.jar")); VirtualFile jar = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempJar); assertNotNull(jar); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java index fd0d51a5c211..f25cf977f48b 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/VirtualFilePointerTest.java @@ -141,7 +141,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { } @Test - public void testDelete() throws IOException { + public void testDelete() { File fileToDelete = tempDir.newFile("toDelete.txt"); LoggingListener fileToDeleteListener = new LoggingListener(); VirtualFilePointer fileToDeletePointer = createPointerByFile(fileToDelete, fileToDeleteListener); @@ -458,7 +458,7 @@ public class VirtualFilePointerTest extends BareTestFixtureTestCase { } @Test - public void testDoubleDispose() throws IOException { + public void testDoubleDispose() { File file = tempDir.newFile("f1"); VirtualFile vFile = getVirtualFile(file); Disposable disposable = Disposer.newDisposable(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/local/CanonicalPathMapTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/local/CanonicalPathMapTest.java index ec96d8330566..cb9bfcd11516 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/local/CanonicalPathMapTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/impl/local/CanonicalPathMapTest.java @@ -11,7 +11,6 @@ import org.junit.Rule; import org.junit.Test; import java.io.File; -import java.io.IOException; import java.util.Collection; import java.util.NavigableSet; @@ -129,7 +128,7 @@ public class CanonicalPathMapTest { } @Test - public void remappedSymLinkReportsOriginalWatchedPath() throws IOException { + public void remappedSymLinkReportsOriginalWatchedPath() { IoTestUtil.assumeSymLinkCreationIsSupported(); // Tests the situation where the watch root is a symlink AND REMAPPED by the native file watcher. diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index a5f49ad4b12f..9fe6af7f692a 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -251,7 +251,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { } @Test - public void testUnicodeName() throws IOException { + public void testUnicodeName() { String name = getUnicodeName(); assumeTrue(name != null); File childFile = tempDir.newFile(name + ".txt"); @@ -264,7 +264,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { } @Test - public void testFindRoot() throws IOException { + public void testFindRoot() { assertNull(myFS.findFileByPath("wrong_path")); if (SystemInfo.isWindows) { @@ -471,7 +471,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { } @Test - public void testBadFileNameUnderUnix() throws IOException { + public void testBadFileNameUnderUnix() { assumeUnix(); File file = tempDir.newFile("test\\file.txt"); @@ -511,7 +511,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { } @Test - public void testCopyToPointDir() throws IOException { + public void testCopyToPointDir() { File sub = tempDir.newDirectory("sub"); File file = tempDir.newFile("file.txt"); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java index 2aad218f3a3c..13d947b4e596 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java @@ -34,7 +34,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @After - public void tearDown() throws IOException { + public void tearDown() { VirtualFile root = refreshAndFind(myTempDir.getRoot()); // purge VFS to avoid persisting these specific file names through to the next launch VfsTestUtil.deleteFile(root); @@ -73,7 +73,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testCircularLink() throws Exception { + public void testCircularLink() { File upDir = myTempDir.newDirectory("sub"); File upLinkFile = createSymLink(upDir.getPath(), upDir.getPath() + "/up_link"); VirtualFile upLinkVFile = refreshAndFind(upLinkFile); @@ -94,7 +94,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testMutualRecursiveLinks() throws Exception { + public void testMutualRecursiveLinks() { File circularDir1 = myTempDir.newDirectory("dir1"); File circularDir2 = myTempDir.newDirectory("dir2"); File circularLink1 = createSymLink(circularDir2.getPath(), circularDir1 + "/link1"); @@ -108,7 +108,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testDuplicateLinks() throws Exception { + public void testDuplicateLinks() { File targetDir = myTempDir.newDirectory("target"); File link1 = createSymLink(targetDir.getPath(), myTempDir.getRoot() + "/link1"); File link2 = createSymLink(targetDir.getPath(), myTempDir.getRoot() + "/link2"); @@ -116,7 +116,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testSidewaysRecursiveLink() throws Exception { + public void testSidewaysRecursiveLink() { File a = myTempDir.newDirectory("a"); File b = createTestDir(a, "b"); File link1 = createSymLink(SystemInfo.isWindows ? a.getPath() : "../../" + a.getName(), b.getPath() + "/link1"); @@ -130,7 +130,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testVisitAllNonRecursiveLinks() throws Exception { + public void testVisitAllNonRecursiveLinks() { File target = myTempDir.newDirectory("target"); File child = createTestDir(target, "child"); File link1 = createSymLink(target.getPath(), myTempDir.getRoot() + "/link1"); @@ -141,7 +141,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testTargetIsWritable() throws Exception { + public void testTargetIsWritable() { File targetFile = myTempDir.newFile("target.txt"); File linkFile = createSymLink(targetFile.getPath(), myTempDir.getRoot() + "/link"); VirtualFile linkVFile = refreshAndFind(linkFile); @@ -328,7 +328,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testTraversePathBehindLink() throws Exception { + public void testTraversePathBehindLink() { File topDir = myTempDir.newDirectory("top"); File subDir1 = createTestDir(topDir, "sub1"); File link = createSymLink(subDir1.getPath(), myTempDir.getRoot() + "/link"); @@ -404,7 +404,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testCircularSymlinksMustBeDetected() throws IOException { + public void testCircularSymlinksMustBeDetected() { File top = myTempDir.newDirectory("top"); File sub1 = createTestDir(top, "sub1"); File link = createSymLink(top.getPath(), sub1.getPath() + "/link"); @@ -429,7 +429,7 @@ public class SymlinkHandlingTest extends BareTestFixtureTestCase { } @Test - public void testCircularSymlinksMustBeDetectedEvenForAsideLinks() throws IOException { + public void testCircularSymlinksMustBeDetectedEvenForAsideLinks() { File top = myTempDir.newDirectory("top"); File sub1 = createTestDir(top, "s1"); File ss1 = createTestDir(sub1, "ss1"); diff --git a/platform/testFramework/src/com/intellij/testFramework/rules/TempDirectory.java b/platform/testFramework/src/com/intellij/testFramework/rules/TempDirectory.java index ff1bffe5498d..bce53c1dde34 100644 --- a/platform/testFramework/src/com/intellij/testFramework/rules/TempDirectory.java +++ b/platform/testFramework/src/com/intellij/testFramework/rules/TempDirectory.java @@ -71,9 +71,9 @@ public class TempDirectory extends ExternalResource { /** * Creates a new directory with the given relative path from the root temp directory. Throws an exception if such a directory already exists. */ - public @NotNull File newDirectory(@NotNull String relativePath) throws IOException { + public @NotNull File newDirectory(@NotNull String relativePath) { Path dir = Paths.get(getRoot().getPath(), relativePath); - if (Files.exists(dir)) throw new IOException("Already exists: " + dir); + if (Files.exists(dir)) throw new IllegalArgumentException("Already exists: " + dir); makeDirectories(dir); return dir.toFile(); } @@ -81,35 +81,50 @@ public class TempDirectory extends ExternalResource { /** * Creates a new directory with random name under the root temp directory. */ - public @NotNull File newDirectory() throws IOException { - return FileUtil.createTempDirectory(getRoot(), "dir" + myNextDirNameSuffix.incrementAndGet(), null); + public @NotNull File newDirectory() { + try { + return FileUtil.createTempDirectory(getRoot(), "dir" + myNextDirNameSuffix.incrementAndGet(), null); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } } /** * Creates a new file with the given relative path from the root temp directory. Throws an exception if such a file already exists. */ - public @NotNull File newFile(@NotNull String relativePath) throws IOException { + public @NotNull File newFile(@NotNull String relativePath) { return newFile(relativePath, null); } /** * Creates a new file with the given relative path from the root temp directory. Throws an exception if such a file already exists. */ - public @NotNull File newFile(@NotNull String relativePath, byte @Nullable [] content) throws IOException { + public @NotNull File newFile(@NotNull String relativePath, byte @Nullable [] content) { Path file = Paths.get(getRoot().getPath(), relativePath); - if (Files.exists(file)) throw new IOException("Already exists: " + file); - makeDirectories(file.getParent()); - Files.createFile(file); - if (content != null) { - Files.write(file, content); + if (Files.exists(file)) throw new IllegalArgumentException("Already exists: " + file); + try { + makeDirectories(file.getParent()); + Files.createFile(file); + if (content != null) { + Files.write(file, content); + } + } + catch (IOException e) { + throw new UncheckedIOException(e); } return file.toFile(); } - private static void makeDirectories(Path path) throws IOException { - if (!Files.isDirectory(path)) { - makeDirectories(path.getParent()); - Files.createDirectory(path); + private static void makeDirectories(Path path) { + try { + if (!Files.isDirectory(path)) { + makeDirectories(path.getParent()); + Files.createDirectory(path); + } + } + catch (IOException e) { + throw new UncheckedIOException(e); } } @@ -117,7 +132,7 @@ public class TempDirectory extends ExternalResource { * @deprecated use {@link #newDirectory(String)}} instead */ @Deprecated - public @NotNull File newFolder(@NotNull String relativePath) throws IOException { + public @NotNull File newFolder(@NotNull String relativePath) { return newDirectory(relativePath); } @@ -125,7 +140,7 @@ public class TempDirectory extends ExternalResource { * @deprecated use {@link #newDirectory()} instead */ @Deprecated - public @NotNull File newFolder() throws IOException { + public @NotNull File newFolder() { return newDirectory(); } } \ No newline at end of file diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java index fd1de54ab58d..608a865e38d8 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java @@ -96,7 +96,7 @@ public abstract class FileAttributesReadingTest { } @Test - public void directory() throws IOException { + public void directory() { File file = tempDir.newDirectory("dir"); FileAttributes attributes = getAttributes(file); @@ -319,7 +319,7 @@ public abstract class FileAttributesReadingTest { } @Test - public void innerJunctionResolve() throws IOException { + public void innerJunctionResolve() { assumeTrue("vista-or-newer expected but got: "+SystemInfo.getOsNameAndVersion(), SystemInfo.isWinVistaOrNewer); File file = tempDir.newFile("dir/file.txt"); @@ -425,7 +425,7 @@ public abstract class FileAttributesReadingTest { } @Test - public void subst() throws IOException { + public void subst() { IoTestUtil.assumeWindows(); tempDir.newFile("file.txt"); // just to populate a directory @@ -522,7 +522,7 @@ public abstract class FileAttributesReadingTest { } @Test - public void permissionsCloning() throws IOException { + public void permissionsCloning() { assumeUnix(); File donor = tempDir.newFile("donor"); diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilHeavyTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilHeavyTest.java index e116d6f206e3..b7e678678cec 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilHeavyTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilHeavyTest.java @@ -78,7 +78,7 @@ public class FileUtilHeavyTest { assertNull(result.get("dir21")); } - private void setupVisitorTestDirectories() throws IOException { + private void setupVisitorTestDirectories() { tempDir.newFile("dir1/1"); tempDir.newFile("dir1/2"); tempDir.newFile("dir2/1"); @@ -98,39 +98,39 @@ public class FileUtilHeavyTest { } @Test - public void nonExistingFile() throws IOException { + public void nonExistingFile() { File first = tempDir.newFile("first"); assertThat(FileUtil.findFileInProvidedPath(first.getPath() + "123", first.getName() + "123")).isNullOrEmpty(); } @Test - public void existingFileInDirectory() throws IOException { + public void existingFileInDirectory() { File first = tempDir.newFile("first"); assertThat(FileUtil.findFileInProvidedPath(tempDir.getRoot().getPath(), "first")).isEqualTo(first.getPath()); } @Test - public void existingFile() throws IOException { + public void existingFile() { File first = tempDir.newFile("first"); assertThat(FileUtil.findFileInProvidedPath(first.getPath(), "first")).isEqualTo(first.getPath()); } @Test - public void twoFilesOrderInDirectory() throws IOException { + public void twoFilesOrderInDirectory() { File first = tempDir.newFile("first"); tempDir.newFile("second"); assertThat(FileUtil.findFileInProvidedPath(tempDir.getRoot().getPath(), "first", "second")).isEqualTo(first.getPath()); } @Test - public void twoFilesOrderInDirectory2() throws IOException { + public void twoFilesOrderInDirectory2() { tempDir.newFile("first"); File second = tempDir.newFile("second"); assertThat(FileUtil.findFileInProvidedPath(tempDir.getRoot().getPath(), "second", "first")).isEqualTo(second.getPath()); } @Test - public void twoFilesOrder() throws IOException { + public void twoFilesOrder() { File first = tempDir.newFile("first"); tempDir.newFile("second"); assertThat(FileUtil.findFileInProvidedPath(first.getPath(), "first", "second")).isEqualTo(first.getPath()); diff --git a/updater/testSrc/com/intellij/updater/UtilsTest.java b/updater/testSrc/com/intellij/updater/UtilsTest.java index ffbc6b1eb26b..2c9f01923c35 100644 --- a/updater/testSrc/com/intellij/updater/UtilsTest.java +++ b/updater/testSrc/com/intellij/updater/UtilsTest.java @@ -61,7 +61,7 @@ public class UtilsTest { } @Test - public void testDeleteLockedFileOnWindows() throws Exception { + public void testDeleteLockedFileOnWindows() { IoTestUtil.assumeWindows(); File f = tempDir.newFile("temp_file");