Skip to content

Commit

Permalink
Some extra unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kirilenkobm committed Jul 31, 2023
1 parent 9a49d21 commit 432508b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 149 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/view/StatusBarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/DirExplorerTestUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
50 changes: 18 additions & 32 deletions src/test/kotlin/model/ExplorerDirectoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
// }
}
32 changes: 31 additions & 1 deletion src/test/kotlin/model/FileSystemEntityFactoryTest.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/service/DirectoryContentServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class DirectoryContentServiceTest {
@Test
fun updateSortOrder() {
}
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/service/EntityActionsHandlerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class EntityActionsHandlerTest {
@Test
fun performEntityAction() {
}
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/service/ThumbnailGenerationServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions src/test/kotlin/service/ZipArchiveServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ package service
import org.junit.jupiter.api.Test

class ZipArchiveServiceTest {

@Test
fun getJob() {
}

@Test
fun getCoroutineContext() {
}

@Test
fun startExtraction() {
}
Expand Down
100 changes: 0 additions & 100 deletions src/test/kotlin/state/AppStateTest.kt

This file was deleted.

0 comments on commit 432508b

Please sign in to comment.