Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump the java-test-dependencies group with 2 updates #184

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<slf4j.version>2.0.9</slf4j.version>

<!-- test dependencies -->
<junit.jupiter.version>5.9.1</junit.jupiter.version>
<mockito.version>4.9.0</mockito.version>
<junit.jupiter.version>5.10.1</junit.jupiter.version>
<mockito.version>5.2.0</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<jimfs.version>1.3.0</jimfs.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.GroupPrincipal;
Expand All @@ -71,6 +72,7 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -454,7 +456,7 @@ public void setup() throws IOException {
when(ciphertextPath.getFilePath()).thenReturn(ciphertextFilePath);
when(openCryptoFiles.getOrCreate(ciphertextFilePath)).thenReturn(openCryptoFile);
when(ciphertextFilePath.getName(3)).thenReturn(mock(CryptoPath.class, "path.c9r"));
when(openCryptoFile.newFileChannel(any(), any())).thenReturn(fileChannel);
when(openCryptoFile.newFileChannel(any(), any(FileAttribute[].class))).thenReturn(fileChannel);
}

@Nested
Expand Down Expand Up @@ -861,7 +863,7 @@ public class Copy {
private final CryptoPath cleartextTargetParent = mock(CryptoPath.class, "cleartextTargetParent");
private final Path ciphertextTargetParent = mock(Path.class, "ciphertextTargetParent");
private final Path ciphertextTargetDirParent = mock(Path.class, "ciphertextTargetDirParent");
private final FileChannel ciphertextTargetDirFileChannel = mock(FileChannel.class);
private final FileChannel ciphertextTargetDirDirFileFileChannel = mock(FileChannel.class);

@BeforeEach
public void setup() throws IOException, ReflectiveOperationException {
Expand All @@ -872,7 +874,7 @@ public void setup() throws IOException, ReflectiveOperationException {

when(cryptoPathMapper.getCiphertextDir(cleartextTargetParent)).thenReturn(new CiphertextDirectory("41", ciphertextTargetParent));
when(cryptoPathMapper.getCiphertextDir(cleartextDestination)).thenReturn(new CiphertextDirectory("42", ciphertextDestinationDir));
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), Mockito.any())).thenReturn(ciphertextTargetDirFileChannel);
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), Mockito.any())).thenReturn(ciphertextTargetDirDirFileFileChannel);
}

@Test
Expand Down Expand Up @@ -954,14 +956,15 @@ public void copyFile() throws IOException {

@Test
public void copyDirectory() throws IOException {
when(physicalFsProv.newFileChannel(Mockito.eq(ciphertextDestinationDirFile), Mockito.any(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
when(cryptoPathMapper.getCiphertextFileType(cleartextSource)).thenReturn(CiphertextFileType.DIRECTORY);
when(cryptoPathMapper.getCiphertextFileType(cleartextDestination)).thenThrow(NoSuchFileException.class);
Mockito.doThrow(new NoSuchFileException("ciphertextDestinationDirFile")).when(physicalFsProv).checkAccess(ciphertextDestinationFile);

inTest.copy(cleartextSource, cleartextDestination);

verify(readonlyFlag, atLeast(1)).assertWritable();
verify(ciphertextTargetDirFileChannel).write(any(ByteBuffer.class));
verify(ciphertextTargetDirDirFileFileChannel).write(any(ByteBuffer.class));
verify(physicalFsProv).createDirectory(ciphertextDestinationDir);
verify(dirIdProvider, Mockito.never()).delete(Mockito.any());
verify(cryptoPathMapper, Mockito.never()).invalidatePathMapping(Mockito.any());
Expand All @@ -981,7 +984,7 @@ public void copyDirectoryReplaceExisting() throws IOException {
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.REPLACE_EXISTING);

verify(readonlyFlag).assertWritable();
verify(ciphertextTargetDirFileChannel, Mockito.never()).write(any(ByteBuffer.class));
verify(ciphertextTargetDirDirFileFileChannel, Mockito.never()).write(any(ByteBuffer.class));
verify(physicalFsProv, Mockito.never()).createDirectory(Mockito.any());
verify(dirIdProvider, Mockito.never()).delete(Mockito.any());
verify(cryptoPathMapper, Mockito.never()).invalidatePathMapping(Mockito.any());
Expand All @@ -1001,8 +1004,9 @@ public void moveDirectoryCopyBasicAttributes() throws IOException {
when(srcAttrs.lastModifiedTime()).thenReturn(lastModifiedTime);
when(srcAttrs.lastAccessTime()).thenReturn(lastAccessTime);
when(srcAttrs.creationTime()).thenReturn(createTime);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(BasicFileAttributes.class), Mockito.any())).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(BasicFileAttributeView.class), Mockito.any())).thenReturn(dstAttrView);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(BasicFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(BasicFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);

inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);

Expand All @@ -1020,8 +1024,9 @@ public void moveDirectoryCopyFileOwnerAttributes() throws IOException {
FileOwnerAttributeView srcAttrsView = mock(FileOwnerAttributeView.class);
FileOwnerAttributeView dstAttrView = mock(FileOwnerAttributeView.class);
when(srcAttrsView.getOwner()).thenReturn(owner);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextSourceDir), Mockito.same(FileOwnerAttributeView.class), Mockito.any())).thenReturn(srcAttrsView);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(FileOwnerAttributeView.class), Mockito.any())).thenReturn(dstAttrView);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextSourceDir), Mockito.same(FileOwnerAttributeView.class), any(LinkOption[].class))).thenReturn(srcAttrsView);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(FileOwnerAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);

inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);

Expand All @@ -1042,8 +1047,9 @@ public void moveDirectoryCopyPosixAttributes() throws IOException {
PosixFileAttributeView dstAttrView = mock(PosixFileAttributeView.class);
when(srcAttrs.group()).thenReturn(group);
when(srcAttrs.permissions()).thenReturn(permissions);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(PosixFileAttributes.class), Mockito.any())).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(PosixFileAttributeView.class), Mockito.any())).thenReturn(dstAttrView);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(PosixFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(PosixFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);

inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);

Expand All @@ -1064,8 +1070,9 @@ public void moveDirectoryCopyDosAttributes() throws IOException {
when(srcAttrs.isHidden()).thenReturn(true);
when(srcAttrs.isReadOnly()).thenReturn(true);
when(srcAttrs.isSystem()).thenReturn(true);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(DosFileAttributes.class), Mockito.any())).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(DosFileAttributeView.class), Mockito.any())).thenReturn(dstAttrView);
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(DosFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(DosFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);

inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);

Expand All @@ -1091,7 +1098,7 @@ public void moveDirectoryReplaceExistingNonEmpty() throws IOException {
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.REPLACE_EXISTING);
});
verify(readonlyFlag).assertWritable();
verify(ciphertextTargetDirFileChannel, Mockito.never()).write(any(ByteBuffer.class));
verify(ciphertextTargetDirDirFileFileChannel, Mockito.never()).write(any(ByteBuffer.class));
verify(physicalFsProv, Mockito.never()).createDirectory(Mockito.any());
verify(dirIdProvider, Mockito.never()).delete(Mockito.any());
verify(cryptoPathMapper, Mockito.never()).invalidatePathMapping(Mockito.any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setup() {
Mockito.when(cryptor.fileNameCryptor()).thenReturn(fileNameCryptor);
Mockito.when(pathToVault.resolve("d")).thenReturn(dataRoot);
Mockito.when(vaultConfig.getShorteningThreshold()).thenReturn(220);
Mockito.when(fileSystem.getPath(ArgumentMatchers.anyString(), ArgumentMatchers.any())).thenAnswer(invocation -> {
Mockito.when(fileSystem.getPath(ArgumentMatchers.anyString(), ArgumentMatchers.any(String[].class))).thenAnswer(invocation -> {
String first = invocation.getArgument(0);
if (invocation.getArguments().length == 1) {
return cryptoPathFactory.getPath(fileSystem, first);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/cryptomator/cryptofs/SymlinksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.spi.FileSystemProvider;

public class SymlinksTest {
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testCreateSymbolicLink() throws IOException {
inTest.createSymbolicLink(cleartextPath, target);

ArgumentCaptor<ByteBuffer> bytesWritten = ArgumentCaptor.forClass(ByteBuffer.class);
Mockito.verify(underlyingFsProvider).createDirectory(Mockito.eq(ciphertextPath), Mockito.any());
Mockito.verify(underlyingFsProvider).createDirectory(Mockito.eq(ciphertextPath), Mockito.any(FileAttribute[].class));
Mockito.verify(openCryptoFiles).writeCiphertextFile(Mockito.eq(symlinkFilePath), Mockito.any(), bytesWritten.capture());
Assertions.assertEquals("/symlink/target/path", StandardCharsets.UTF_8.decode(bytesWritten.getValue()).toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public void setup() throws IOException {
ciphertextBasicAttr = Mockito.mock(BasicFileAttributes.class);
ciphertextPosixAttr = Mockito.mock(PosixFileAttributes.class);
ciphertextDosAttr = Mockito.mock(DosFileAttributes.class);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(BasicFileAttributes.class), any())).thenReturn(ciphertextBasicAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(PosixFileAttributes.class), any())).thenReturn(ciphertextPosixAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(DosFileAttributes.class), any())).thenReturn(ciphertextDosAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(BasicFileAttributes.class), any(LinkOption[].class))).thenReturn(ciphertextBasicAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(PosixFileAttributes.class), any(LinkOption[].class))).thenReturn(ciphertextPosixAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextRawPath), Mockito.same(DosFileAttributes.class), any(LinkOption[].class))).thenReturn(ciphertextDosAttr);

Mockito.when(pathMapper.getCiphertextFileType(cleartextPath)).thenReturn(CiphertextFileType.FILE);
Mockito.when(pathMapper.getCiphertextFilePath(cleartextPath)).thenReturn(ciphertextPath);
Expand Down