Search in sources :

Example 1 with FileChannelMock

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()));
}
Also used : FileChannelMock(org.cryptomator.cryptofs.mocks.FileChannelMock) NoSuchFileException(java.nio.file.NoSuchFileException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 2 with FileChannelMock

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);
}
Also used : FileChannelMock(org.cryptomator.cryptofs.mocks.FileChannelMock) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) NoSuchFileException(java.nio.file.NoSuchFileException) FileTime(java.nio.file.attribute.FileTime) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 3 with FileChannelMock

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()));
}
Also used : FileChannelMock(org.cryptomator.cryptofs.mocks.FileChannelMock) NoSuchFileException(java.nio.file.NoSuchFileException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 4 with FileChannelMock

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()));
}
Also used : FileChannelMock(org.cryptomator.cryptofs.mocks.FileChannelMock) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Aggregations

BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 FileChannelMock (org.cryptomator.cryptofs.mocks.FileChannelMock)4 Test (org.junit.Test)4 NoSuchFileException (java.nio.file.NoSuchFileException)3 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)1 FileTime (java.nio.file.attribute.FileTime)1