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
class UserRepository(private val service: UserService) { | |
private suspend fun search(query: String, page: Int, perPage: Int, sort: String) = service.search(query, page, perPage, sort).await() | |
private suspend fun getDetail(login: String) = service.getDetail(login).await() | |
private suspend fun getRepos(login: String) = service.getRepos(login).await() | |
private suspend fun getFollowers(login: String) = service.getFollowers(login).await() |
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
interface UserService { | |
@GET("search/users") | |
fun search(@Query("q") query: String, | |
@Query("page") page: Int, | |
@Query("per_page") perPage: Int, | |
@Query("sort") sort: String, | |
@Query("client_id") clientId: String = BuildConfig.GithubClientId, | |
@Query("client_secret") clientSecret: String = BuildConfig.GithubClientSecret): Deferred<Result> |
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
class SearchUserViewModel(private val repository: UserRepository): BaseViewModel() { | |
private val searchQuery = MutableLiveData<String>() | |
private val listing = map(searchQuery) { repository.searchUsersWithPagination(it) } | |
val networkState: LiveData<NetworkState>? = switchMap(listing) { it.networkState } | |
val usersFetched: LiveData<PagedList<User>> = switchMap(listing) { it.pagedList } | |
override fun onCleared() { | |
super.onCleared() |
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
/** | |
* Instrumented tests for [JobListFragment] | |
*/ | |
@RunWith(AndroidJUnit4::class) | |
@LargeTest | |
class TIJobList { | |
@Rule | |
@JvmField | |
val activityRule = ActivityTestRule(SingleFragmentActivity::class.java, true, true) |
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
/** | |
* Remote [FirebaseFirestore] datasource only used for tests | |
* @param listApprovedJobs: Mocked [Query] used to return a custom list of jobs. | |
*/ | |
fun remoteDataSourceTestModule(listApprovedJobs: Query) = module { | |
factory { mockk<FirebaseFirestore>(relaxed = true) } | |
single { | |
object : JobDao(get()) { | |
override fun listApprovedJobs() = listApprovedJobs | |
} as JobDao |
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
/** | |
* We use a separate [Application] for tests to prevent initializing release modules. | |
* On the contrary, we will provide inside our tests custom [Module]. | |
* | |
* See [io.nobullshit.nobullshit.TIRunner]. | |
*/ | |
class TIBaseApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
startKoin(this, emptyList()) |
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
class JobListFragment : BaseFragment() { | |
val jobDao: JobDao by inject() | |
... | |
} |
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
class BaseApplication: Application() { | |
override fun onCreate() { | |
super.onCreate() | |
startKoin(this, appComponent) | |
} | |
} |
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
@Singleton | |
@Component( | |
modules = [ | |
AndroidInjectionModule::class, | |
DataModule::class, | |
MainActivityModule::class] | |
) | |
interface AppComponent { | |
@Component.Builder | |
interface Builder { |
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
/** | |
* App Components | |
*/ | |
val appComponent: List<Module> = listOf(remoteDataSourceModule) |