1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-21 22:27:29 +00:00

Migrate service/dao test objects to open class adapters for re-usability

This commit is contained in:
Ammar Githam 2021-06-12 13:13:11 +09:00
parent 8253328788
commit dd227751af
2 changed files with 161 additions and 158 deletions

View File

@ -0,0 +1,154 @@
package awais.instagrabber.common
import awais.instagrabber.db.dao.AccountDao
import awais.instagrabber.db.entities.Account
import awais.instagrabber.repositories.*
import awais.instagrabber.repositories.responses.*
open class UserServiceAdapter : UserService {
override suspend fun getUserInfo(uid: Long): WrappedUser {
TODO("Not yet implemented")
}
override suspend fun getUsernameInfo(username: String): WrappedUser {
TODO("Not yet implemented")
}
override suspend fun getUserFriendship(uid: Long): FriendshipStatus {
TODO("Not yet implemented")
}
override suspend fun search(timezoneOffset: Float, query: String): UserSearchResponse {
TODO("Not yet implemented")
}
}
open class FriendshipServiceAdapter : FriendshipService {
override suspend fun change(action: String, id: Long, form: Map<String, String>): FriendshipChangeResponse {
TODO("Not yet implemented")
}
override suspend fun toggleRestrict(action: String, form: Map<String, String>): FriendshipRestrictResponse {
TODO("Not yet implemented")
}
override suspend fun getList(userId: Long, type: String, queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun changeMute(action: String, form: Map<String, String>): FriendshipChangeResponse {
TODO("Not yet implemented")
}
}
open class StoriesServiceAdapter : StoriesService {
override suspend fun fetch(mediaId: Long): String {
TODO("Not yet implemented")
}
override suspend fun getFeedStories(): String {
TODO("Not yet implemented")
}
override suspend fun fetchHighlights(uid: Long): String {
TODO("Not yet implemented")
}
override suspend fun fetchArchive(queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun getUserStory(url: String): String {
TODO("Not yet implemented")
}
override suspend fun respondToSticker(storyId: String, stickerId: String, action: String, form: Map<String, String>): StoryStickerResponse {
TODO("Not yet implemented")
}
override suspend fun seen(queryParams: Map<String, String>, form: Map<String, String>): String {
TODO("Not yet implemented")
}
}
open class MediaServiceAdapter : MediaService {
override suspend fun fetch(mediaId: Long): MediaInfoResponse {
TODO("Not yet implemented")
}
override suspend fun fetchLikes(mediaId: String, action: String): LikersResponse {
TODO("Not yet implemented")
}
override suspend fun action(action: String, mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun editCaption(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun translate(form: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun uploadFinish(retryContext: String, queryParams: Map<String, String>, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun delete(mediaId: String, mediaType: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun archive(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
}
open class GraphQLServiceAdapter : GraphQLService {
override suspend fun fetch(queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun getUser(username: String): String {
TODO("Not yet implemented")
}
override suspend fun getPost(shortcode: String): String {
TODO("Not yet implemented")
}
override suspend fun getTag(tag: String): String {
TODO("Not yet implemented")
}
override suspend fun getLocation(locationId: Long): String {
TODO("Not yet implemented")
}
}
open class AccountDaoAdapter : AccountDao {
override suspend fun getAllAccounts(): List<Account> {
TODO("Not yet implemented")
}
override suspend fun findAccountByUid(uid: String): Account? {
TODO("Not yet implemented")
}
override suspend fun insertAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun updateAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAllAccounts() {
TODO("Not yet implemented")
}
}

View File

@ -2,166 +2,15 @@ package awais.instagrabber.viewmodels
import androidx.lifecycle.SavedStateHandle
import androidx.test.ext.junit.runners.AndroidJUnit4
import awais.instagrabber.db.dao.AccountDao
import awais.instagrabber.common.*
import awais.instagrabber.db.datasources.AccountDataSource
import awais.instagrabber.db.entities.Account
import awais.instagrabber.db.repositories.AccountRepository
import awais.instagrabber.repositories.*
import awais.instagrabber.repositories.responses.*
import awais.instagrabber.webservices.*
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
internal class ProfileFragmentViewModelTest {
private val userService = object : UserService {
override suspend fun getUserInfo(uid: Long): WrappedUser {
TODO("Not yet implemented")
}
override suspend fun getUsernameInfo(username: String): WrappedUser {
TODO("Not yet implemented")
}
override suspend fun getUserFriendship(uid: Long): FriendshipStatus {
TODO("Not yet implemented")
}
override suspend fun search(timezoneOffset: Float, query: String): UserSearchResponse {
TODO("Not yet implemented")
}
}
private val friendshipService = object : FriendshipService {
override suspend fun change(action: String, id: Long, form: Map<String, String>): FriendshipChangeResponse {
TODO("Not yet implemented")
}
override suspend fun toggleRestrict(action: String, form: Map<String, String>): FriendshipRestrictResponse {
TODO("Not yet implemented")
}
override suspend fun getList(userId: Long, type: String, queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun changeMute(action: String, form: Map<String, String>): FriendshipChangeResponse {
TODO("Not yet implemented")
}
}
private val storiesService = object : StoriesService {
override suspend fun fetch(mediaId: Long): String {
TODO("Not yet implemented")
}
override suspend fun getFeedStories(): String {
TODO("Not yet implemented")
}
override suspend fun fetchHighlights(uid: Long): String {
TODO("Not yet implemented")
}
override suspend fun fetchArchive(queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun getUserStory(url: String): String {
TODO("Not yet implemented")
}
override suspend fun respondToSticker(storyId: String, stickerId: String, action: String, form: Map<String, String>): StoryStickerResponse {
TODO("Not yet implemented")
}
override suspend fun seen(queryParams: Map<String, String>, form: Map<String, String>): String {
TODO("Not yet implemented")
}
}
private val mediaService = object : MediaService {
override suspend fun fetch(mediaId: Long): MediaInfoResponse {
TODO("Not yet implemented")
}
override suspend fun fetchLikes(mediaId: String, action: String): LikersResponse {
TODO("Not yet implemented")
}
override suspend fun action(action: String, mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun editCaption(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun translate(form: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun uploadFinish(retryContext: String, queryParams: Map<String, String>, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun delete(mediaId: String, mediaType: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun archive(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
}
private val graphQLService = object : GraphQLService {
override suspend fun fetch(queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun getUser(username: String): String {
TODO("Not yet implemented")
}
override suspend fun getPost(shortcode: String): String {
TODO("Not yet implemented")
}
override suspend fun getTag(tag: String): String {
TODO("Not yet implemented")
}
override suspend fun getLocation(locationId: Long): String {
TODO("Not yet implemented")
}
}
private val accountDao = object : AccountDao{
override suspend fun getAllAccounts(): List<Account> {
TODO("Not yet implemented")
}
override suspend fun findAccountByUid(uid: String): Account? {
TODO("Not yet implemented")
}
override suspend fun insertAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun updateAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAccounts(vararg accounts: Account) {
TODO("Not yet implemented")
}
override suspend fun deleteAllAccounts() {
TODO("Not yet implemented")
}
}
@Test
fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle(
@ -169,12 +18,12 @@ internal class ProfileFragmentViewModelTest {
"username" to ""
)
)
val userRepository = UserRepository(userService)
val friendshipRepository = FriendshipRepository(friendshipService)
val storiesRepository = StoriesRepository(storiesService)
val mediaRepository = MediaRepository(mediaService)
val graphQLRepository = GraphQLRepository(graphQLService)
val accountDataSource = AccountDataSource(accountDao)
val userRepository = UserRepository(UserServiceAdapter())
val friendshipRepository = FriendshipRepository(FriendshipServiceAdapter())
val storiesRepository = StoriesRepository(StoriesServiceAdapter())
val mediaRepository = MediaRepository(MediaServiceAdapter())
val graphQLRepository = GraphQLRepository(GraphQLServiceAdapter())
val accountDataSource = AccountDataSource(AccountDaoAdapter())
val accountRepository = AccountRepository(accountDataSource)
val viewModel = ProfileFragmentViewModel(
state,