-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/explore viewmodel 테스트 #34
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
10094fd
Refactor: FileUtil -> FileManager class로 변경
Guri999 e3659a6
Feat: Test setting
Guri999 8286c88
Test: ExploreViewModel Test Init 파일 초기화 상태 테스트
Guri999 f7c51fb
Test: ClickFile Repository에 insert 후 PDF 화면으로 이동 테스트
Guri999 e63fbd2
Test: ClickFolder Folder 화면으로 이동
Guri999 10fa093
Chore: FileUtil.kt -> FileManager 파일명 변경
Guri999 3ffe81c
Fix: Make this interface functional or replace it with a function type.
Guri999 9602db0
Chore: FileManager -> FileManagerImpl
Guri999 ee5ed9c
Chore: Move Dummy Properties to TestFile
Guri999 5ae19fd
Feat: create Coroutine Rule
Guri999 a75a998
Refactor: Mockk Annotation
Guri999 9884049
Chore: code alignment
Guri999 7b6a0eb
Feat: RecentRepository Test Class 생성
Guri999 61a4225
Feat: set Turbin
Guri999 b220d61
Feat: change Test name
Guri999 ef1fdcb
Fix: viewModel 파라미터 수정
Guri999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import kr.co.convention.setNamespace | ||
|
||
plugins { | ||
alias(libs.plugins.seedocs.library) | ||
} | ||
|
||
setNamespace("core.testing") | ||
|
||
dependencies { | ||
api(libs.mockk) | ||
api(libs.kotlinx.coroutines.test) | ||
api(libs.mockk.android) | ||
api(libs.koin.test) | ||
api(libs.koin.junit) | ||
api(projects.core.data) | ||
api(libs.turbine) | ||
} |
24 changes: 24 additions & 0 deletions
24
core/testing/src/main/java/kr/co/testing/repository/TestRecentRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.co.testing.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kr.co.data.repository.RecentRepository | ||
import kr.co.model.FileInfo | ||
|
||
class TestRecentRepository: RecentRepository { | ||
|
||
private val recentFilesFlow: MutableStateFlow<List<FileInfo>> = | ||
MutableStateFlow(emptyList()) | ||
|
||
override suspend fun insert(recentFile: FileInfo) { | ||
recentFilesFlow.update { it + recentFile } | ||
} | ||
|
||
override fun get(): Flow<List<FileInfo>> = | ||
recentFilesFlow | ||
|
||
override suspend fun delete(recentFile: FileInfo) { | ||
recentFilesFlow.update { it - recentFile } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/testing/src/main/java/kr/co/testing/rule/CoroutineTestRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kr.co.testing.rule | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
class CoroutineTestRule : TestWatcher() { | ||
override fun starting(description: Description?) { | ||
super.starting(description) | ||
Dispatchers.setMain(UnconfinedTestDispatcher()) | ||
} | ||
|
||
override fun finished(description: Description?) { | ||
Dispatchers.resetMain() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package kr.co.di | ||
|
||
import kr.co.explore.ExploreViewModel | ||
import kr.co.util.FileManagerImpl | ||
import kr.co.util.FileManager | ||
import org.koin.core.module.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val exploreModule = | ||
module { | ||
viewModel { | ||
ExploreViewModel( | ||
get() | ||
get(), | ||
get<FileManagerImpl>(), | ||
) | ||
} | ||
|
||
single<FileManager> { | ||
FileManagerImpl() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kr.co.util | ||
|
||
import kr.co.model.FileInfo | ||
|
||
internal fun interface FileManager { | ||
suspend fun readPDFOrDirectory(path: String): List<FileInfo> | ||
} |
44 changes: 44 additions & 0 deletions
44
feature/explore/src/main/java/kr/co/util/FileManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package kr.co.util | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kr.co.model.FileInfo | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.attribute.BasicFileAttributes | ||
import java.nio.file.attribute.FileTime | ||
import java.time.LocalDateTime | ||
import java.time.ZoneId | ||
|
||
internal class FileManagerImpl: FileManager { | ||
override suspend fun readPDFOrDirectory( | ||
path: String, | ||
): List<FileInfo> = withContext(Dispatchers.IO) { | ||
File(path).listFiles()?.filter { !it.isHidden && (it.isDirectory || it.extension == PDF) } | ||
?.map { | ||
val attributes = getFileAttributes(it) | ||
FileInfo( | ||
name = it.name, | ||
path = it.path, | ||
type = FileInfo.Type.from(it.extension), | ||
isDirectory = it.isDirectory, | ||
size = it.length(), | ||
isHidden = it.isHidden, | ||
createdAt = attributes.creationTime().toLocalDateTime(), | ||
lastModified = attributes.lastModifiedTime().toLocalDateTime(), | ||
) | ||
} ?: emptyList() | ||
} | ||
|
||
private fun getFileAttributes(file: File): BasicFileAttributes = | ||
Files.readAttributes(file.toPath(), BasicFileAttributes::class.java) | ||
|
||
private fun FileTime.toLocalDateTime(): LocalDateTime = | ||
LocalDateTime.ofInstant(this.toInstant(), ZoneId.systemDefault()) | ||
|
||
companion object { | ||
internal const val DEFAULT_STORAGE = "/storage/emulated/0" | ||
|
||
private const val PDF = "pdf" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel의 의존성은 FileManager 인터페이스로 두고, 주입되는 클래스를 구체클래스인 FileManagerImpl로 하는 것이 의존성 주입 목적에 맞을 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 이름 바꾸면서 바꼇네요 수정하겠습니다