diff options
Diffstat (limited to 'app/src/test/java/org/the_jk/cleversync/io')
| -rw-r--r-- | app/src/test/java/org/the_jk/cleversync/io/UtilsTest.kt | 51 |
1 files changed, 51 insertions, 0 deletions
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) + } +} |
