-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused method and refactor Board Api tests
- Loading branch information
Michael Lien
committed
Feb 1, 2021
1 parent
15a0094
commit 74cfb86
Showing
10 changed files
with
192 additions
and
113 deletions.
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
6 changes: 0 additions & 6 deletions
6
app/src/main/java/tw/y_studio/ptt/source/remote/board/IPopularRemoteDataSource.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 |
---|---|---|
@@ -1,13 +1,7 @@ | ||
package tw.y_studio.ptt.source.remote.board | ||
|
||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoardTemp | ||
|
||
interface IPopularRemoteDataSource { | ||
|
||
fun getPopularBoardData(page: Int, count: Int): MutableList<HotBoardTemp> | ||
|
||
suspend fun getPopularBoards(): HotBoard | ||
|
||
fun disposeAll() | ||
} |
15 changes: 1 addition & 14 deletions
15
app/src/main/java/tw/y_studio/ptt/source/remote/board/PopularRemoteDataSourceImpl.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 |
---|---|---|
@@ -1,25 +1,12 @@ | ||
package tw.y_studio.ptt.source.remote.board | ||
|
||
import tw.y_studio.ptt.api.PopularBoardListAPI | ||
import tw.y_studio.ptt.api.board.BoardApiService | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoardTemp | ||
|
||
class PopularRemoteDataSourceImpl( | ||
private val boardApiService: BoardApiService, | ||
private val popularBoardListAPI: PopularBoardListAPI | ||
private val boardApiService: BoardApiService | ||
) : IPopularRemoteDataSource { | ||
|
||
@Throws(Exception::class) | ||
override fun getPopularBoardData(page: Int, count: Int): MutableList<HotBoardTemp> { | ||
return popularBoardListAPI.refresh(page, count) | ||
} | ||
|
||
override suspend fun getPopularBoards(): HotBoard { | ||
return boardApiService.getPopularBoard() | ||
} | ||
|
||
override fun disposeAll() { | ||
popularBoardListAPI.close() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -46,6 +46,5 @@ class HotBoardsViewModel( | |
|
||
override fun onCleared() { | ||
super.onCleared() | ||
popularRemoteDataSource.disposeAll() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/sharedTest/java/tw/y_studio/ptt/MainCoroutineRule.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,29 @@ | ||
package tw.y_studio.ptt | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestCoroutineScope | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
import kotlin.coroutines.ContinuationInterceptor | ||
|
||
/** | ||
* Created by Michael.Lien | ||
* on 2021/2/1 | ||
*/ | ||
@ExperimentalCoroutinesApi | ||
class MainCoroutineRule : TestWatcher(), TestCoroutineScope by TestCoroutineScope() { | ||
|
||
override fun starting(description: Description?) { | ||
super.starting(description) | ||
Dispatchers.setMain(this.coroutineContext[ContinuationInterceptor] as CoroutineDispatcher) | ||
} | ||
|
||
override fun finished(description: Description?) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/sharedTest/java/tw/y_studio/ptt/TestJsonFileUtils.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,27 @@ | ||
package tw.y_studio.ptt | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
/** | ||
* Created by Michael.Lien | ||
* on 2021/2/1 | ||
*/ | ||
object TestJsonFileUtils { | ||
fun loadJsonFile(fileName: String): String { | ||
val classloader = javaClass.classLoader | ||
val inputStream = classloader.getResourceAsStream(fileName) | ||
val builder = StringBuilder() | ||
val buffer = CharArray(1024) | ||
val reader = BufferedReader(InputStreamReader(inputStream)) | ||
var n: Int | ||
while (true) { | ||
n = reader.read(buffer) | ||
if (n < 0) break | ||
builder.append(buffer, 0, n) | ||
} | ||
inputStream.close() | ||
|
||
return builder.toString() | ||
} | ||
} |
53 changes: 28 additions & 25 deletions
53
app/src/test/java/tw/y_studio/ptt/source/remote/board/PopularRemoteDataSourceTest.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
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,23 @@ | ||
{ | ||
"list": [ | ||
{ | ||
"bid": "string", | ||
"brdname": "string", | ||
"title": "string", | ||
"flag": 0, | ||
"type": "string", | ||
"class": "string", | ||
"nuser": 0, | ||
"moderators": [ | ||
"string" | ||
], | ||
"reason": "string", | ||
"read": true, | ||
"total": 0, | ||
"last_post_time": 0, | ||
"stat_attr": 0, | ||
"level_idx": "string" | ||
} | ||
], | ||
"next_idx": "string" | ||
} |
Oops, something went wrong.