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) {
}
}
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) {
}
}
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) {
}
}
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());
}
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);
}
Aggregations