Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myleague.apitesting
- import android.util.Log
- import androidx.lifecycle.MutableLiveData
- import com.example.myleague.model.league.LeagueDetailResponse
- import com.example.myleague.model.league.LeaguesDetailModel
- import com.example.myleague.model.league.LeaguesResponse
- import com.example.myleague.network.ApiService
- import org.junit.Before
- import org.junit.Test
- import org.mockito.Mock
- import org.mockito.MockitoAnnotations
- import retrofit2.Call
- import retrofit2.Callback
- import retrofit2.Response
- class LeaguesViewModelTest {
- @Mock
- private val leagusListData = MutableLiveData<ArrayList<LeaguesDetailModel>>()
- @Mock
- private val listItems = ArrayList<LeaguesDetailModel>()
- @Before
- fun setUp(){
- MockitoAnnotations.initMocks(this)
- }
- @Test
- fun setLeaguesList() {
- ApiService().getApi().getLeagues().enqueue(object : Callback<LeaguesResponse> {
- override fun onFailure(call: Call<LeaguesResponse>, t: Throwable) {
- Log.i("FAILED GET ", "LIST OF LEAGUES ERROR : ${t} ")
- }
- override fun onResponse(
- call: Call<LeaguesResponse>,
- response: Response<LeaguesResponse>
- ) {
- response.body()?.leagues?.let {
- getLeageuBadge()
- }
- leagusListData.postValue(listItems)
- }
- })
- }
- @Test
- fun getLeageuBadge() {
- ApiService().getApi().getLeaguesById("4346").enqueue(object : Callback<LeagueDetailResponse> {
- override fun onFailure(call: Call<LeagueDetailResponse>, t: Throwable) {
- Log.i("FAILED GET ", "LEAGUE DETAIL ERROR : ${t} ")
- }
- override fun onResponse(
- call: Call<LeagueDetailResponse>,
- response: Response<LeagueDetailResponse>
- ) {
- response.body()?.leagues?.let {
- for (i in it) {
- if (i?.strBadge != null) {
- Log.i("${i.strLeague} ", " ${i.strBadge}")
- listItems.add(i)
- }
- }
- }
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement