use of org.cryptomator.cryptofs.mocks.FileChannelMock in project cryptofs by cryptomator.
the class CopyOperationTest method testCopyExistingFileToNonExistingFileOnDifferentFileSystem.
@Test
public void testCopyExistingFileToNonExistingFileOnDifferentFileSystem() throws IOException {
FileChannelMock targetFile = new FileChannelMock(100);
BasicFileAttributes aPathFromFsAAttributes = mock(BasicFileAttributes.class);
when(provider.readAttributes(aPathFromFsA, BasicFileAttributes.class)).thenReturn(aPathFromFsAAttributes);
when(provider.readAttributes(aPathFromFsB, BasicFileAttributes.class)).thenThrow(new NoSuchFileException("aPathFromFsB"));
when(provider.newFileChannel(aPathFromFsA, EnumSet.of(READ))).thenReturn(new FileChannelMock(repeat(42).times(20).asByteBuffer()));
when(provider.newFileChannel(aPathFromFsB, EnumSet.of(CREATE_NEW, WRITE))).thenReturn(targetFile);
inTest.copy(aPathFromFsA, aPathFromFsB);
assertThat(targetFile.data(), contains(repeat(42).times(20).asByteBuffer()));
}
use of org.cryptomator.cryptofs.mocks.FileChannelMock in project cryptofs by cryptomator.
the class CopyOperationTest method testCopyExistingFileToNonExistingFileOnDifferentFileSystemWithCopyAttributesFlagSetsFileTimes.
@Test
public void testCopyExistingFileToNonExistingFileOnDifferentFileSystemWithCopyAttributesFlagSetsFileTimes() throws IOException {
FileTime creationTime = FileTime.fromMillis(3883483);
FileTime lastModifiedTime = FileTime.fromMillis(3883484);
FileTime lastAccessTime = FileTime.fromMillis(3883485);
FileChannelMock targetFile = new FileChannelMock(100);
BasicFileAttributes aPathFromFsAAttributes = mock(BasicFileAttributes.class);
BasicFileAttributeView aPathFromFsBAttributeView = mock(BasicFileAttributeView.class);
when(provider.readAttributes(aPathFromFsA, BasicFileAttributes.class)).thenReturn(aPathFromFsAAttributes);
when(provider.getFileAttributeView(aPathFromFsB, BasicFileAttributeView.class)).thenReturn(aPathFromFsBAttributeView);
when(provider.readAttributes(aPathFromFsB, BasicFileAttributes.class)).thenThrow(new NoSuchFileException("aPathFromFsB"));
when(provider.newFileChannel(aPathFromFsA, EnumSet.of(READ))).thenReturn(new FileChannelMock(repeat(42).times(20).asByteBuffer()));
when(provider.newFileChannel(aPathFromFsB, EnumSet.of(CREATE_NEW, WRITE))).thenReturn(targetFile);
when(aPathFromFsAAttributes.creationTime()).thenReturn(creationTime);
when(aPathFromFsAAttributes.lastModifiedTime()).thenReturn(lastModifiedTime);
when(aPathFromFsAAttributes.lastAccessTime()).thenReturn(lastAccessTime);
inTest.copy(aPathFromFsA, aPathFromFsB, COPY_ATTRIBUTES);
assertThat(targetFile.data(), contains(repeat(42).times(20).asByteBuffer()));
verify(aPathFromFsBAttributeView).setTimes(lastModifiedTime, lastAccessTime, creationTime);
}
use of org.cryptomator.cryptofs.mocks.FileChannelMock in project cryptofs by cryptomator.
the class CopyOperationTest method testCopyExistingFileToNonExistingFileOnDifferentFileSystemWithCopyAttributesFlagDoesNotSetFileTimesIfNoAttributeViewIsAvailable.
@Test
public void testCopyExistingFileToNonExistingFileOnDifferentFileSystemWithCopyAttributesFlagDoesNotSetFileTimesIfNoAttributeViewIsAvailable() throws IOException {
FileChannelMock targetFile = new FileChannelMock(100);
BasicFileAttributes aPathFromFsAAttributes = mock(BasicFileAttributes.class);
when(provider.readAttributes(aPathFromFsA, BasicFileAttributes.class)).thenReturn(aPathFromFsAAttributes);
when(provider.getFileAttributeView(aPathFromFsB, BasicFileAttributeView.class)).thenReturn(null);
when(provider.readAttributes(aPathFromFsB, BasicFileAttributes.class)).thenThrow(new NoSuchFileException("aPathFromFsB"));
when(provider.newFileChannel(aPathFromFsA, EnumSet.of(READ))).thenReturn(new FileChannelMock(repeat(42).times(20).asByteBuffer()));
when(provider.newFileChannel(aPathFromFsB, EnumSet.of(CREATE_NEW, WRITE))).thenReturn(targetFile);
inTest.copy(aPathFromFsA, aPathFromFsB, COPY_ATTRIBUTES);
assertThat(targetFile.data(), contains(repeat(42).times(20).asByteBuffer()));
}
use of org.cryptomator.cryptofs.mocks.FileChannelMock in project cryptofs by cryptomator.
the class CopyOperationTest method testCopyExistingFileToExistingFileOnDifferentFileSystemWithReplaceExistingFlag.
@Test
public void testCopyExistingFileToExistingFileOnDifferentFileSystemWithReplaceExistingFlag() throws IOException {
FileChannelMock targetFile = new FileChannelMock(100);
BasicFileAttributes aPathFromFsAAttributes = mock(BasicFileAttributes.class);
BasicFileAttributes aPathFromFsBAttributes = mock(BasicFileAttributes.class);
when(provider.readAttributes(aPathFromFsA, BasicFileAttributes.class)).thenReturn(aPathFromFsAAttributes);
when(provider.readAttributes(aPathFromFsB, BasicFileAttributes.class)).thenReturn(aPathFromFsBAttributes);
when(provider.newFileChannel(aPathFromFsA, EnumSet.of(READ))).thenReturn(new FileChannelMock(repeat(42).times(20).asByteBuffer()));
when(provider.newFileChannel(aPathFromFsB, EnumSet.of(CREATE_NEW, WRITE))).thenReturn(targetFile);
inTest.copy(aPathFromFsA, aPathFromFsB, REPLACE_EXISTING);
verify(provider).delete(aPathFromFsB);
assertThat(targetFile.data(), contains(repeat(42).times(20).asByteBuffer()));
}
Aggregations