File tree Expand file tree Collapse file tree 3 files changed +73
-3
lines changed
main/java/org/cryptomator/integrations/mount
test/java/org/cryptomator/integrations/mount Expand file tree Collapse file tree 3 files changed +73
-3
lines changed Original file line number Diff line number Diff line change 11package org .cryptomator .integrations .mount ;
22
3- import java .nio .file .Path ;
4-
53/**
64 * Handle to control the lifecycle of a mounted file system.
75 * <p>
@@ -14,7 +12,7 @@ public interface Mount extends AutoCloseable {
1412 *
1513 * @return Absolute path to the mountpoint.
1614 */
17- Path getMountpoint ();
15+ Mountpoint getMountpoint ();
1816
1917 /**
2018 * Unmounts the mounted Volume.
Original file line number Diff line number Diff line change 1+ package org .cryptomator .integrations .mount ;
2+
3+ import java .net .URI ;
4+ import java .nio .file .Path ;
5+
6+ /**
7+ * A {@link Mount}'s mount point. There are two types of mount points: Path-based and URI-based.
8+ */
9+ public sealed interface Mountpoint permits Mountpoint .WithPath , Mountpoint .WithUri {
10+
11+ /**
12+ * Gets an URI representation of this mount point.
13+ *
14+ * @return an URI pointing to this mount point
15+ */
16+ URI uri ();
17+
18+ static Mountpoint forUri (URI uri ) {
19+ return new WithUri (uri );
20+ }
21+
22+ static Mountpoint forPath (Path path ) {
23+ return new WithPath (path );
24+ }
25+
26+ record WithUri (URI uri ) implements Mountpoint {
27+ }
28+
29+ record WithPath (Path path ) implements Mountpoint {
30+
31+ public URI uri () {
32+ return path .toUri ();
33+ }
34+
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ package org .cryptomator .integrations .mount ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .DisplayName ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import java .net .URI ;
8+ import java .nio .file .Path ;
9+
10+ public class MountpointTest {
11+
12+ @ Test
13+ @ DisplayName ("MountPoint.forPath()" )
14+ public void testForPath () {
15+ var path = Path .of ("/foo/bar" );
16+ var mountPoint = Mountpoint .forPath (path );
17+
18+ if (mountPoint instanceof Mountpoint .WithPath m ) {
19+ Assertions .assertEquals (path , m .path ());
20+ Assertions .assertEquals (URI .create ("file:/foo/bar" ), mountPoint .uri ());
21+ } else {
22+ Assertions .fail ();
23+ }
24+ }
25+
26+ @ Test
27+ @ DisplayName ("MountPoint.forUri()" )
28+ public void testForUri () {
29+ var uri = URI .create ("webdav://localhost:8080/foo/bar" );
30+ var mountPoint = Mountpoint .forUri (uri );
31+
32+ Assertions .assertTrue (mountPoint instanceof Mountpoint .WithUri );
33+ Assertions .assertEquals (uri , mountPoint .uri ());
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments