From 47d3bf13023b3d62ef4530d439c3bd3e1d2baf9e Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 14 Jul 2024 23:41:26 +0200 Subject: Add Directory#liveList and make Directory#list() direct Also move the LiveData outside Directory.Content. A lot of code doesn't care about Directory content in two seconds, they want to know it now. Also, the LiveData returned is one of the annoying one where the content isn't correct until someone observes it. This makes more sense this way. --- .../java/org/the_jk/cleversync/LocalTreeTest.kt | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'app/src/test') diff --git a/app/src/test/java/org/the_jk/cleversync/LocalTreeTest.kt b/app/src/test/java/org/the_jk/cleversync/LocalTreeTest.kt index d9a9bd8..951fd62 100644 --- a/app/src/test/java/org/the_jk/cleversync/LocalTreeTest.kt +++ b/app/src/test/java/org/the_jk/cleversync/LocalTreeTest.kt @@ -29,9 +29,17 @@ class LocalTreeTest { @Test fun empty() { val content = tree.list() - assertThat(content.directories.safeValue()).isEmpty() - assertThat(content.files.safeValue()).isEmpty() - assertThat(content.links.safeValue()).isEmpty() + assertThat(content.directories).isEmpty() + assertThat(content.files).isEmpty() + assertThat(content.links).isEmpty() + } + + @Test + fun emptyLive() { + val content = tree.liveList().safeValue() + assertThat(content?.directories).isEmpty() + assertThat(content?.files).isEmpty() + assertThat(content?.links).isEmpty() } @Test @@ -39,21 +47,21 @@ class LocalTreeTest { val foo = tree.createDirectory("foo") assertThat(foo.name).isEqualTo("foo") val fooContent = foo.list() - assertThat(fooContent.directories.safeValue()).isEmpty() - assertThat(fooContent.files.safeValue()).isEmpty() - assertThat(fooContent.links.safeValue()).isEmpty() + assertThat(fooContent.directories).isEmpty() + assertThat(fooContent.files).isEmpty() + assertThat(fooContent.links).isEmpty() val content = tree.list() - assertThat(content.directories.safeValue()).contains(foo) - assertThat(content.files.safeValue()).isEmpty() - assertThat(content.links.safeValue()).isEmpty() + assertThat(content.directories).contains(foo) + assertThat(content.files).isEmpty() + assertThat(content.links).isEmpty() } @Test fun observeCreateDirectory() { - val content = tree.list() + val content = tree.liveList() var dir: Directory? = null - content.directories.observeForever { list -> - if (list.size == 1) dir = list[0] + content.observeForever { + if (it.directories.size == 1) dir = it.directories[0] } tree.createDirectory("foo") while (dir == null) { @@ -66,11 +74,11 @@ class LocalTreeTest { fun createFile() { val foo = tree.createFile("foo") // Files are not created until you write to them. - assertThat(tree.list().files.safeValue()).isEmpty() + assertThat(tree.list().files).isEmpty() foo.write().use { os -> os.write(byteArrayOf(1, 2, 3, 4)) } - assertThat(tree.list().files.safeValue()).contains(foo) + assertThat(tree.list().files).contains(foo) assertThat(foo.size).isEqualTo(4.toULong()) foo.read().use { assertThat(it.readBytes()).isEqualTo(byteArrayOf(1, 2, 3, 4)) @@ -88,7 +96,7 @@ class LocalTreeTest { assertThat(foo.size).isEqualTo(4.toULong()) } assertThat(foo.size).isEqualTo(1.toULong()) - assertThat(tree.list().files.safeValue()).hasSize(1) + assertThat(tree.list().files).hasSize(1) foo.read().use { assertThat(it.readBytes()).isEqualTo(byteArrayOf(127)) } -- cgit v1.2.3-70-g09d2