Search in sources :

Example 46 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project jimfs by google.

the class ConfigurationTest method testFileSystemForDefaultWindowsConfiguration.

@Test
public void testFileSystemForDefaultWindowsConfiguration() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.windows());
    assertThat(fs.getRootDirectories()).containsExactlyElementsIn(ImmutableList.of(fs.getPath("C:\\"))).inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("C:\\work"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).isEqualTo(4L * 1024 * 1024 * 1024);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic");
    Files.createFile(fs.getPath("C:\\foo"));
    try {
        Files.createFile(fs.getPath("C:\\FOO"));
        fail();
    } catch (FileAlreadyExistsException expected) {
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 47 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project jimfs by google.

the class ConfigurationTest method testFileSystemForCustomConfiguration.

@Test
public void testFileSystemForCustomConfiguration() throws IOException {
    Configuration config = Configuration.builder(PathType.unix()).setRoots("/").setWorkingDirectory("/hello/world").setNameCanonicalNormalization(NFD, CASE_FOLD_UNICODE).setNameDisplayNormalization(NFC).setPathEqualityUsesCanonicalForm(true).setBlockSize(10).setMaxSize(100).setMaxCacheSize(50).setAttributeViews("unix").setDefaultAttributeValue("posix:permissions", PosixFilePermissions.fromString("---------")).build();
    FileSystem fs = Jimfs.newFileSystem(config);
    assertThat(fs.getRootDirectories()).containsExactlyElementsIn(ImmutableList.of(fs.getPath("/"))).inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("/hello/world"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).isEqualTo(100);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic", "owner", "posix", "unix");
    Files.createFile(fs.getPath("/foo"));
    assertThat(Files.getAttribute(fs.getPath("/foo"), "posix:permissions")).isEqualTo(PosixFilePermissions.fromString("---------"));
    try {
        Files.createFile(fs.getPath("/FOO"));
        fail();
    } catch (FileAlreadyExistsException expected) {
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 48 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project j2objc by google.

the class FilesTest method test_createFile.

/* J2ObjC removed: mockito unsupported
    @Mock
    private Path mockPath;
    @Mock
    private Path mockPath2;
    @Mock
    private FileSystem mockFileSystem;
    @Mock
    private FileSystemProvider mockFileSystemProvider;
     */
/* J2ObjC removed: mockito unsupported
    @Before
    public void setUp() throws Exception {
        when(mockPath.getFileSystem()).thenReturn(mockFileSystem);
        when(mockPath2.getFileSystem()).thenReturn(mockFileSystem);
        when(mockFileSystem.provider()).thenReturn(mockFileSystemProvider);
    }
     */
/* J2ObjC removed: mockito unsupported
    @Test
    public void test_newInputStream() throws IOException {
        try (InputStream is = new ByteArrayInputStream(new byte[0])) {

            when(mockFileSystemProvider.newInputStream(mockPath, READ)).thenReturn(is);

            assertSame(is, Files.newInputStream(mockPath, READ));

            verify(mockFileSystemProvider).newInputStream(mockPath, READ);
        }
    }
     */
/* J2ObjC removed: mockito unsupported
    @Test
    public void test_newOutputStream() throws IOException {
        try (OutputStream os = new ByteArrayOutputStream()) {

            when(mockFileSystemProvider.newOutputStream(mockPath, APPEND)).thenReturn(os);

            assertSame(os, Files.newOutputStream(mockPath, APPEND));

            verify(mockFileSystemProvider).newOutputStream(mockPath, APPEND);
        }
    }
     */
/* J2ObjC removed: mockito unsupported
    @Test
    public void test_newByteChannel() throws IOException {
        try (FileChannel sfc = FileChannel.open(filesSetup.getDataFilePath())) {
            HashSet<OpenOption> openOptions = new HashSet<>();
            openOptions.add(READ);

            when(mockFileSystemProvider.newByteChannel(mockPath, openOptions)).thenReturn(sfc);

            assertSame(sfc, Files.newByteChannel(mockPath, READ));

            verify(mockFileSystemProvider).newByteChannel(mockPath, openOptions);
        }
    }
     */
@Test
public void test_createFile() throws IOException {
    assertFalse(Files.exists(filesSetup.getTestPath()));
    Files.createFile(filesSetup.getTestPath());
    assertTrue(Files.exists(filesSetup.getTestPath()));
    // File with unicode name.
    Path unicodeFilePath = filesSetup.getPathInTestDir("परीक्षण फ़ाइल");
    Files.createFile(unicodeFilePath);
    Files.exists(unicodeFilePath);
    // When file exists.
    try {
        Files.createFile(filesSetup.getDataFilePath());
        fail();
    } catch (FileAlreadyExistsException expected) {
    }
}
Also used : Path(java.nio.file.Path) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) Test(org.junit.Test)

Example 49 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project j2objc by google.

the class FileAlreadyExistsExceptionTest method test_constructor$String$String$String.

public void test_constructor$String$String$String() {
    FileAlreadyExistsException exception = new FileAlreadyExistsException("file", "otherFile", "reason");
    assertEquals("file", exception.getFile());
    assertEquals("otherFile", exception.getOtherFile());
    assertEquals("reason", exception.getReason());
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 50 with FileAlreadyExistsException

use of java.nio.file.FileAlreadyExistsException in project j2objc by google.

the class FileAlreadyExistsExceptionTest method test_constructor$String.

public void test_constructor$String() {
    FileAlreadyExistsException exception = new FileAlreadyExistsException("file");
    assertEquals("file", exception.getFile());
    assertNull(exception.getOtherFile());
    assertNull(exception.getReason());
    assertTrue(exception instanceof FileSystemException);
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileSystemException(java.nio.file.FileSystemException)

Aggregations

FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)104 Path (java.nio.file.Path)49 IOException (java.io.IOException)44 File (java.io.File)24 NoSuchFileException (java.nio.file.NoSuchFileException)22 Test (org.junit.Test)15 FileNotFoundException (java.io.FileNotFoundException)10 FileSystemException (java.nio.file.FileSystemException)9 AccessDeniedException (java.nio.file.AccessDeniedException)8 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)8 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)8 NotDirectoryException (java.nio.file.NotDirectoryException)7 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)5 CopyOption (java.nio.file.CopyOption)5 FileSystem (java.nio.file.FileSystem)5 FileVisitResult (java.nio.file.FileVisitResult)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 FileSystemLoopException (java.nio.file.FileSystemLoopException)4