From 432508b3612c0c0c4ef40bb4faf2db3dc43c836f Mon Sep 17 00:00:00 2001 From: Bogdan Kirilenko Date: Mon, 31 Jul 2023 03:53:44 +0200 Subject: [PATCH] Some extra unit tests --- src/main/kotlin/view/StatusBarView.kt | 2 +- .../directoryviews/AbstractDirectoryView.kt | 2 +- src/test/kotlin/DirExplorerTestUtil.kt | 3 +- .../kotlin/model/ExplorerDirectoryTest.kt | 50 ++++----- .../model/FileSystemEntityFactoryTest.kt | 32 +++++- .../service/DirectoryContentServiceTest.kt | 2 +- .../service/EntityActionsHandlerTest.kt | 2 +- .../service/ThumbnailGenerationServiceTest.kt | 2 +- .../kotlin/service/ZipArchiveServiceTest.kt | 9 -- src/test/kotlin/state/AppStateTest.kt | 100 ------------------ 10 files changed, 55 insertions(+), 149 deletions(-) delete mode 100644 src/test/kotlin/state/AppStateTest.kt diff --git a/src/main/kotlin/view/StatusBarView.kt b/src/main/kotlin/view/StatusBarView.kt index 2fd981e..f0b34ae 100644 --- a/src/main/kotlin/view/StatusBarView.kt +++ b/src/main/kotlin/view/StatusBarView.kt @@ -31,7 +31,7 @@ class StatusBarView : JPanel(), CoroutineScope, DirectoryObserver, SettingsObser private var job = Job() override val coroutineContext: CoroutineContext - get() = Dispatchers.Main + job + get() = Dispatchers.IO + job init { setupView() diff --git a/src/main/kotlin/view/directoryviews/AbstractDirectoryView.kt b/src/main/kotlin/view/directoryviews/AbstractDirectoryView.kt index 63e1efc..117f05a 100644 --- a/src/main/kotlin/view/directoryviews/AbstractDirectoryView.kt +++ b/src/main/kotlin/view/directoryviews/AbstractDirectoryView.kt @@ -19,7 +19,7 @@ abstract class AbstractDirectoryView: { private val job = Job() override val coroutineContext: CoroutineContext - get() = Dispatchers.Main + job + get() = Dispatchers.IO + job abstract fun updateView() diff --git a/src/test/kotlin/DirExplorerTestUtil.kt b/src/test/kotlin/DirExplorerTestUtil.kt index e9f657a..ba8c779 100644 --- a/src/test/kotlin/DirExplorerTestUtil.kt +++ b/src/test/kotlin/DirExplorerTestUtil.kt @@ -62,8 +62,7 @@ object DirExplorerTestUtil { } // Create a symlink - // Note: this might not work on all file systems - Files.createSymbolicLink(tempDir.resolve("symlink"), tempDir.resolve("file1.txt")) + Files.createSymbolicLink(tempDir.resolve("root_to_subfile1"), subdir1.resolve("subfile1.txt")) return tempDir } diff --git a/src/test/kotlin/model/ExplorerDirectoryTest.kt b/src/test/kotlin/model/ExplorerDirectoryTest.kt index e4b2760..7eb2078 100644 --- a/src/test/kotlin/model/ExplorerDirectoryTest.kt +++ b/src/test/kotlin/model/ExplorerDirectoryTest.kt @@ -17,44 +17,30 @@ class ExplorerDirectoryTest { private lateinit var explorerDirectory: ExplorerDirectory private lateinit var emptyDirectory: ExplorerDirectory - @BeforeEach - fun setup() { + @Test + fun getContents() = runBlocking { tempDir = DirExplorerTestUtil.setupTestDirectory() explorerDirectory = ExplorerDirectory(tempDir.toString()) emptyDirectory = ExplorerDirectory(tempDir.resolve("emptydir").toString()) - } - - @AfterEach - fun teardown() { - DirExplorerTestUtil.teardownTestDirectory() - } - - @Test - fun getContents() = runBlocking { val contents = explorerDirectory.getContents() assertEquals(11, contents.size) - // TODO - } - - @Test - fun isEmpty() { assertFalse(explorerDirectory.isEmpty) assertTrue(emptyDirectory.isEmpty) + DirExplorerTestUtil.teardownTestDirectory() } - - @Test - fun getItemsCount() { - } - - @Test - fun getTotalSize() { - } - - @Test - fun invalidateCache() { - } - - @Test - fun getPath() { - } +// @Test +// fun getItemsCount() { +// } +// +// @Test +// fun getTotalSize() { +// } +// +// @Test +// fun invalidateCache() { +// } +// +// @Test +// fun getPath() { +// } } \ No newline at end of file diff --git a/src/test/kotlin/model/FileSystemEntityFactoryTest.kt b/src/test/kotlin/model/FileSystemEntityFactoryTest.kt index 232bcd6..310daac 100644 --- a/src/test/kotlin/model/FileSystemEntityFactoryTest.kt +++ b/src/test/kotlin/model/FileSystemEntityFactoryTest.kt @@ -1,10 +1,40 @@ package model import org.junit.jupiter.api.Test +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import kotlin.streams.asSequence +import kotlin.test.assertTrue class FileSystemEntityFactoryTest { + private lateinit var tempDir: Path + private lateinit var explorerDirectory: ExplorerDirectory @Test fun createEntity() { + tempDir = DirExplorerTestUtil.setupTestDirectory() + explorerDirectory = ExplorerDirectory(tempDir.toString()) + val filesInDir = Files.list(Paths.get(tempDir.toString())).asSequence() + for (elem in filesInDir) { + val respectiveEntity = FileSystemEntityFactory.createEntity(elem.toString()) + + // Check the type of the respectiveEntity + when (elem.fileName.toString()) { + "file2.txt", "file1.txt", "file.log", "document1.pdf", "image2.jpeg", "image1.png" -> { + assertTrue(respectiveEntity is ExplorerFile) + } + "root_to_subfile1" -> { + assertTrue(respectiveEntity is ExplorerSymLink) + } + "subdir2", "emptydir", "subdir1" -> { + assertTrue(respectiveEntity is ExplorerDirectory) + } + "archive.zip" -> { + assertTrue(respectiveEntity is ZipArchive) + } + } + } + DirExplorerTestUtil.teardownTestDirectory() } -} \ No newline at end of file +} diff --git a/src/test/kotlin/service/DirectoryContentServiceTest.kt b/src/test/kotlin/service/DirectoryContentServiceTest.kt index d596490..feeecee 100644 --- a/src/test/kotlin/service/DirectoryContentServiceTest.kt +++ b/src/test/kotlin/service/DirectoryContentServiceTest.kt @@ -19,4 +19,4 @@ class DirectoryContentServiceTest { @Test fun updateSortOrder() { } -} \ No newline at end of file +} diff --git a/src/test/kotlin/service/EntityActionsHandlerTest.kt b/src/test/kotlin/service/EntityActionsHandlerTest.kt index 7990414..a83021b 100644 --- a/src/test/kotlin/service/EntityActionsHandlerTest.kt +++ b/src/test/kotlin/service/EntityActionsHandlerTest.kt @@ -7,4 +7,4 @@ class EntityActionsHandlerTest { @Test fun performEntityAction() { } -} \ No newline at end of file +} diff --git a/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt b/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt index 90280f5..22ce9b5 100644 --- a/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt +++ b/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt @@ -55,7 +55,7 @@ class ThumbnailGenerationServiceTest { @Test fun createImageThumbnailSkipsHugeImages() { - // Image with longsize > 6000 must be skipped, expected null + // Image with long-side > 6000 must be skipped, expected null val pathToVeryBigImage = "src/test/resources/tooWideImage.jpg" val dummyFileEntity = ExplorerFile(pathToVeryBigImage) val dummyIcon = FileIconView(dummyFileEntity) diff --git a/src/test/kotlin/service/ZipArchiveServiceTest.kt b/src/test/kotlin/service/ZipArchiveServiceTest.kt index 3e4425c..32814f0 100644 --- a/src/test/kotlin/service/ZipArchiveServiceTest.kt +++ b/src/test/kotlin/service/ZipArchiveServiceTest.kt @@ -3,15 +3,6 @@ package service import org.junit.jupiter.api.Test class ZipArchiveServiceTest { - - @Test - fun getJob() { - } - - @Test - fun getCoroutineContext() { - } - @Test fun startExtraction() { } diff --git a/src/test/kotlin/state/AppStateTest.kt b/src/test/kotlin/state/AppStateTest.kt deleted file mode 100644 index f7d4438..0000000 --- a/src/test/kotlin/state/AppStateTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -package state - -import org.junit.jupiter.api.Test - -import org.junit.jupiter.api.Assertions.* - -class AppStateTest { - - @Test - fun getCurrentExplorerDirectory() { - } - - @Test - fun setCurrentExplorerDirectory() { - } - - @Test - fun getBackStack() { - } - - @Test - fun setBackStack() { - } - - @Test - fun getForwardStack() { - } - - @Test - fun setForwardStack() { - } - - @Test - fun getZipServices() { - } - - @Test - fun getTempZipDirToNameMapping() { - } - - @Test - fun getZipPathToTempDir() { - } - - @Test - fun updateDirectory() { - } - - @Test - fun goHome() { - } - - @Test - fun goUp() { - } - - @Test - fun goBack() { - } - - @Test - fun goForward() { - } - - @Test - fun getFilter() { - } - - @Test - fun getFilterList() { - } - - @Test - fun insideZip() { - } - - @Test - fun updateFilter() { - } - - @Test - fun addDirectoryObserver() { - } - - @Test - fun markObserverForRemoval() { - } - - @Test - fun addZipArchive() { - } - - @Test - fun cleanupAllZipArchives() { - } - - @Test - fun refreshCurrentDirectory() { - } -} \ No newline at end of file