Search in sources :

Example 1 with AppLaunchEvent

use of org.cryptomator.ui.launcher.AppLaunchEvent in project cryptomator by cryptomator.

the class FileOpenRequestHandlerTest method testOpenArgsWithFullQueue.

@Test
@DisplayName("./cryptomator.exe foo (with full event queue)")
public void testOpenArgsWithFullQueue() {
    queue.add(new AppLaunchEvent(AppLaunchEvent.EventType.OPEN_FILE, Collections.emptyList()));
    Assumptions.assumeTrue(queue.remainingCapacity() == 0);
    inTest.handleLaunchArgs(List.of("foo"));
}
Also used : AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with AppLaunchEvent

use of org.cryptomator.ui.launcher.AppLaunchEvent in project cryptomator by cryptomator.

the class FileOpenRequestHandlerTest method testOpenArgsWithCorrectPaths.

@Test
@DisplayName("./cryptomator.exe foo bar")
public void testOpenArgsWithCorrectPaths() {
    inTest.handleLaunchArgs(List.of("foo", "bar"));
    AppLaunchEvent evt = queue.poll();
    Assertions.assertNotNull(evt);
    Collection<Path> paths = evt.getPathsToOpen();
    MatcherAssert.assertThat(paths, CoreMatchers.hasItems(Paths.get("foo"), Paths.get("bar")));
}
Also used : Path(java.nio.file.Path) AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with AppLaunchEvent

use of org.cryptomator.ui.launcher.AppLaunchEvent in project cryptomator by cryptomator.

the class FileOpenRequestHandlerTest method testOpenArgsWithIncorrectPaths.

@Test
@DisplayName("./cryptomator.exe foo (with 'foo' being an invalid path)")
public void testOpenArgsWithIncorrectPaths() {
    FileSystem fs = Mockito.mock(FileSystem.class);
    Mockito.when(fs.getPath("foo")).thenThrow(new InvalidPathException("foo", "foo is not a path"));
    inTest.handleLaunchArgs(fs, List.of("foo"));
    AppLaunchEvent evt = queue.poll();
    Assertions.assertNull(evt);
}
Also used : AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) FileSystem(java.nio.file.FileSystem) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with AppLaunchEvent

use of org.cryptomator.ui.launcher.AppLaunchEvent in project cryptomator by cryptomator.

the class FileOpenRequestHandler method handleLaunchArgs.

// visible for testing
void handleLaunchArgs(FileSystem fs, List<String> args) {
    Collection<Path> pathsToOpen = args.stream().map(str -> {
        try {
            return fs.getPath(str);
        } catch (InvalidPathException e) {
            LOG.trace("Argument not a valid path: {}", str);
            return null;
        }
    }).filter(Objects::nonNull).toList();
    if (!pathsToOpen.isEmpty()) {
        AppLaunchEvent launchEvent = new AppLaunchEvent(AppLaunchEvent.EventType.OPEN_FILE, pathsToOpen);
        tryToEnqueueFileOpenRequest(launchEvent);
    }
}
Also used : Path(java.nio.file.Path) AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) InvalidPathException(java.nio.file.InvalidPathException)

Example 5 with AppLaunchEvent

use of org.cryptomator.ui.launcher.AppLaunchEvent in project cryptomator by cryptomator.

the class FileOpenRequestHandler method openFiles.

private void openFiles(OpenFilesEvent evt) {
    Collection<Path> pathsToOpen = evt.getFiles().stream().map(File::toPath).toList();
    AppLaunchEvent launchEvent = new AppLaunchEvent(AppLaunchEvent.EventType.OPEN_FILE, pathsToOpen);
    tryToEnqueueFileOpenRequest(launchEvent);
}
Also used : Path(java.nio.file.Path) AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent)

Aggregations

AppLaunchEvent (org.cryptomator.ui.launcher.AppLaunchEvent)5 Path (java.nio.file.Path)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 InvalidPathException (java.nio.file.InvalidPathException)2 FileSystem (java.nio.file.FileSystem)1