Skip to content

Commit 6be3413

Browse files
allow path- and uri-based mount points
1 parent 6f6c6a5 commit 6be3413

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

src/main/java/org/cryptomator/integrations/mount/Mount.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package 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.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)