summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-07-15 00:46:18 +0200
committerJoel Klinghed <the_jk@spawned.biz>2024-07-15 00:46:18 +0200
commit427bb4c2ab0ce5cfb988789657c2de3761fec392 (patch)
tree8fe7f9f42c22284df2dc4f038cb04d3c8bc5234d /app/src/test
parentd351b94c9d81513b088572ae72ee8d114b08e1c6 (diff)
Add Utils for parsing path parts to a directory
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/org/the_jk/cleversync/StringUtilsTest.kt40
-rw-r--r--app/src/test/java/org/the_jk/cleversync/io/UtilsTest.kt51
2 files changed, 91 insertions, 0 deletions
diff --git a/app/src/test/java/org/the_jk/cleversync/StringUtilsTest.kt b/app/src/test/java/org/the_jk/cleversync/StringUtilsTest.kt
new file mode 100644
index 0000000..6a36156
--- /dev/null
+++ b/app/src/test/java/org/the_jk/cleversync/StringUtilsTest.kt
@@ -0,0 +1,40 @@
+package org.the_jk.cleversync
+
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class StringUtilsTest {
+ @Test
+ fun splitEmpty() {
+ assertThat(StringUtils.split("", '.', keepEmpty = true)).containsExactly("")
+ assertThat(StringUtils.split("", '.', keepEmpty = false)).isEmpty()
+ }
+
+ @Test
+ fun splitSanity() {
+ assertThat(StringUtils.split("a.bb.a", '.')).containsExactly("a", "bb", "a").inOrder()
+ assertThat(StringUtils.split(".a.bb.a", '.', keepEmpty = true)).containsExactly("", "a", "bb", "a").inOrder()
+ assertThat(StringUtils.split(".a.bb.a", '.', keepEmpty = false)).containsExactly("a", "bb", "a").inOrder()
+ assertThat(StringUtils.split(".a.bb.a.", '.', keepEmpty = true))
+ .containsExactly("", "a", "bb", "a", "").inOrder()
+ assertThat(StringUtils.split(".a.bb.a.", '.', keepEmpty = false)).containsExactly("a", "bb", "a").inOrder()
+ }
+
+ @Test
+ fun splitDouble() {
+ assertThat(StringUtils.split("foo..bar", '.', keepEmpty = true)).containsExactly("foo", "", "bar").inOrder()
+ assertThat(StringUtils.split("foo..bar", '.', keepEmpty = false)).containsExactly("foo", "bar").inOrder()
+ }
+
+ @Test
+ fun splitLimit() {
+ assertThat(StringUtils.split("a.bb.a", '.', limit = 1)).containsExactly("a.bb.a")
+ assertThat(StringUtils.split("a.bb.a", '.', limit = 2)).containsExactly("a", "bb.a").inOrder()
+ assertThat(StringUtils.split("a.bb.a", '.', limit = 3)).containsExactly("a", "bb", "a").inOrder()
+ assertThat(StringUtils.split("a.bb.a.", '.', limit = 3, keepEmpty = true))
+ .containsExactly("a", "bb", "a.").inOrder()
+ assertThat(StringUtils.split("a.bb.a.", '.', limit = 3, keepEmpty = false))
+ .containsExactly("a", "bb", "a").inOrder()
+ assertThat(StringUtils.split("a.bb.a", '.', limit = 1000)).containsExactly("a", "bb", "a").inOrder()
+ }
+}
diff --git a/app/src/test/java/org/the_jk/cleversync/io/UtilsTest.kt b/app/src/test/java/org/the_jk/cleversync/io/UtilsTest.kt
new file mode 100644
index 0000000..56c4051
--- /dev/null
+++ b/app/src/test/java/org/the_jk/cleversync/io/UtilsTest.kt
@@ -0,0 +1,51 @@
+package org.the_jk.cleversync.io
+
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+
+@Config(manifest= Config.NONE)
+@RunWith(RobolectricTestRunner::class)
+class UtilsTest {
+ @get:Rule
+ val folder = TemporaryFolder()
+
+ private lateinit var tree: ModifiableTree
+
+ @Before
+ fun setUp() {
+ tree = TreeFactory.localModifiableTree(folder.root.toPath())
+ }
+
+ @Test
+ fun makeDirectories() {
+ assertThat(Utils.makeDirectories(tree)).isEqualTo(tree)
+ val foo = Utils.makeDirectories(tree, "foo")
+ val foobar = Utils.makeDirectories(tree, "foo", "bar")
+ val foofum = Utils.makeDirectories(tree, "foo/fum")
+ assertThat(foo.name).isEqualTo("foo")
+ assertThat(tree.list().directories).containsExactly(foo)
+ assertThat(foobar.name).isEqualTo("bar")
+ assertThat(foofum.name).isEqualTo("fum")
+ assertThat(foo.list().directories).containsExactly(foobar, foofum)
+ }
+
+ @Test
+ fun openDirectories() {
+ assertThat(Utils.openDirectory(tree)).isEqualTo(tree)
+ assertThat(Utils.openDirectory(tree, "foo")).isNull()
+ assertThat(Utils.openDirectory(tree, "foo", "bar")).isNull()
+ assertThat(Utils.openDirectory(tree, "foo/fum")).isNull()
+ val foo = tree.createDirectory("foo")
+ val foobar = foo.createDirectory("bar")
+ val foofum = foo.createDirectory("fum")
+ assertThat(Utils.openDirectory(tree, "foo")).isEqualTo(foo)
+ assertThat(Utils.openDirectory(tree, "foo", "bar")).isEqualTo(foobar)
+ assertThat(Utils.openDirectory(tree, "foo/fum")).isEqualTo(foofum)
+ }
+}