|
@@ -5,7 +5,13 @@
|
|
*******************************************************************************/
|
|
*******************************************************************************/
|
|
package org.cryptomator.launcher;
|
|
package org.cryptomator.launcher;
|
|
|
|
|
|
|
|
+import org.cryptomator.ui.model.AppLaunchEvent;
|
|
|
|
+import org.hamcrest.CoreMatchers;
|
|
|
|
+import org.hamcrest.MatcherAssert;
|
|
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
+import org.junit.jupiter.api.Assumptions;
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.Mockito;
|
|
import org.mockito.Mockito;
|
|
|
|
|
|
@@ -13,64 +19,55 @@ import java.io.IOException;
|
|
import java.nio.file.FileSystem;
|
|
import java.nio.file.FileSystem;
|
|
import java.nio.file.InvalidPathException;
|
|
import java.nio.file.InvalidPathException;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
-import java.nio.file.attribute.BasicFileAttributes;
|
|
|
|
-import java.nio.file.spi.FileSystemProvider;
|
|
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.util.List;
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
import java.util.concurrent.BlockingQueue;
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
public class FileOpenRequestHandlerTest {
|
|
public class FileOpenRequestHandlerTest {
|
|
|
|
|
|
|
|
+ private FileOpenRequestHandler inTest;
|
|
|
|
+ private BlockingQueue<AppLaunchEvent> queue;
|
|
|
|
+
|
|
|
|
+ @BeforeEach
|
|
|
|
+ public void setup() {
|
|
|
|
+ queue = new ArrayBlockingQueue<>(1);
|
|
|
|
+ inTest = new FileOpenRequestHandler(queue);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
|
|
+ @DisplayName("./cryptomator.exe foo bar")
|
|
public void testOpenArgsWithCorrectPaths() throws IOException {
|
|
public void testOpenArgsWithCorrectPaths() throws IOException {
|
|
- Path p1 = Mockito.mock(Path.class);
|
|
|
|
- Path p2 = Mockito.mock(Path.class);
|
|
|
|
- FileSystem fs = Mockito.mock(FileSystem.class);
|
|
|
|
- FileSystemProvider provider = Mockito.mock(FileSystemProvider.class);
|
|
|
|
- BasicFileAttributes attrs = Mockito.mock(BasicFileAttributes.class);
|
|
|
|
- Mockito.when(p1.getFileSystem()).thenReturn(fs);
|
|
|
|
- Mockito.when(p2.getFileSystem()).thenReturn(fs);
|
|
|
|
- Mockito.when(fs.provider()).thenReturn(provider);
|
|
|
|
- Mockito.when(fs.getPath(Mockito.anyString())).thenReturn(p1, p2);
|
|
|
|
- Mockito.when(provider.readAttributes(Mockito.any(), Mockito.eq(BasicFileAttributes.class))).thenReturn(attrs);
|
|
|
|
|
|
+ inTest.handleLaunchArgs(new String[]{"foo", "bar"});
|
|
|
|
|
|
- BlockingQueue<Path> queue = new ArrayBlockingQueue<>(10);
|
|
|
|
- FileOpenRequestHandler handler = new FileOpenRequestHandler(queue);
|
|
|
|
- handler.handleLaunchArgs(fs, new String[] {"foo", "bar"});
|
|
|
|
-
|
|
|
|
- Assertions.assertEquals(p1, queue.poll());
|
|
|
|
- Assertions.assertEquals(p2, queue.poll());
|
|
|
|
|
|
+ AppLaunchEvent evt = queue.poll();
|
|
|
|
+ Assertions.assertNotNull(evt);
|
|
|
|
+ List<Path> paths = evt.getPathsToOpen().collect(Collectors.toList());
|
|
|
|
+ MatcherAssert.assertThat(paths, CoreMatchers.hasItems(Paths.get("foo"), Paths.get("bar")));
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
|
+ @DisplayName("./cryptomator.exe foo (with 'foo' being an invalid path)")
|
|
public void testOpenArgsWithIncorrectPaths() throws IOException {
|
|
public void testOpenArgsWithIncorrectPaths() throws IOException {
|
|
FileSystem fs = Mockito.mock(FileSystem.class);
|
|
FileSystem fs = Mockito.mock(FileSystem.class);
|
|
- Mockito.when(fs.getPath(Mockito.anyString())).thenThrow(new InvalidPathException("foo", "foo is not a path"));
|
|
|
|
-
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- BlockingQueue<Path> queue = Mockito.mock(BlockingQueue.class);
|
|
|
|
- FileOpenRequestHandler handler = new FileOpenRequestHandler(queue);
|
|
|
|
- handler.handleLaunchArgs(fs, new String[] {"foo"});
|
|
|
|
|
|
+ Mockito.when(fs.getPath("foo")).thenThrow(new InvalidPathException("foo", "foo is not a path"));
|
|
|
|
+ inTest.handleLaunchArgs(fs, new String[]{"foo"});
|
|
|
|
|
|
- Mockito.verifyNoMoreInteractions(queue);
|
|
|
|
|
|
+ AppLaunchEvent evt = queue.poll();
|
|
|
|
+ Assertions.assertNotNull(evt);
|
|
|
|
+ List<Path> paths = evt.getPathsToOpen().collect(Collectors.toList());
|
|
|
|
+ Assertions.assertTrue(paths.isEmpty());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
|
+ @DisplayName("./cryptomator.exe foo (with full event queue)")
|
|
public void testOpenArgsWithFullQueue() throws IOException {
|
|
public void testOpenArgsWithFullQueue() throws IOException {
|
|
- Path p = Mockito.mock(Path.class);
|
|
|
|
- FileSystem fs = Mockito.mock(FileSystem.class);
|
|
|
|
- FileSystemProvider provider = Mockito.mock(FileSystemProvider.class);
|
|
|
|
- BasicFileAttributes attrs = Mockito.mock(BasicFileAttributes.class);
|
|
|
|
- Mockito.when(p.getFileSystem()).thenReturn(fs);
|
|
|
|
- Mockito.when(fs.provider()).thenReturn(provider);
|
|
|
|
- Mockito.when(fs.getPath(Mockito.anyString())).thenReturn(p);
|
|
|
|
- Mockito.when(provider.readAttributes(Mockito.eq(p), Mockito.eq(BasicFileAttributes.class))).thenReturn(attrs);
|
|
|
|
- Mockito.when(attrs.isRegularFile()).thenReturn(true);
|
|
|
|
|
|
+ queue.add(new AppLaunchEvent(Stream.empty()));
|
|
|
|
+ Assumptions.assumeTrue(queue.remainingCapacity() == 0);
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- BlockingQueue<Path> queue = Mockito.mock(BlockingQueue.class);
|
|
|
|
- Mockito.when(queue.offer(Mockito.any())).thenReturn(false);
|
|
|
|
- FileOpenRequestHandler handler = new FileOpenRequestHandler(queue);
|
|
|
|
- handler.handleLaunchArgs(fs, new String[] {"foo"});
|
|
|
|
|
|
+ inTest.handleLaunchArgs(new String[]{"foo"});
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|