1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
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)
}
@Test
fun createFileAndDirectories() {
val file = Utils.createFileAndDirectories(tree, "foo", "bar/test", "1 2 3 4", "hello/file.txt")
file.write().use { out -> out.writer().write("Hello World") }
val file2 = Utils.openFile(tree, "foo/bar/test/1 2 3 4/hello/file.txt")
assertThat(file2).isEqualTo(file)
val foo = tree.openDir("foo")
val bar = foo?.openDir("bar")
val test = bar?.openDir("test")
val nameWithSpaces = test?.openDir("1 2 3 4")
val hello = nameWithSpaces?.openDir("hello")
val file3 = hello?.openFile("file.txt")
assertThat(file3).isEqualTo(file2)
}
}
|