mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[test framework] use UncheckedIOException in TempDirectory to remove unnecessary throws declaration in tests
GitOrigin-RevId: a820f0ec670fad921edd37e92491ef020041903e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b320836ff5
commit
130c116128
@@ -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()) + "!/");
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
+1
-2
@@ -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.
|
||||
|
||||
+4
-4
@@ -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");
|
||||
|
||||
|
||||
+10
-10
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class UtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteLockedFileOnWindows() throws Exception {
|
||||
public void testDeleteLockedFileOnWindows() {
|
||||
IoTestUtil.assumeWindows();
|
||||
|
||||
File f = tempDir.newFile("temp_file");
|
||||
|
||||
Reference in New Issue
Block a user