I think somethings wrong about my code in TeamImplsTest, and i need advice :D This is my code
API interface
interface API {
@GET("lookupteam.php")
fun getTeam(@Query("id") id: String): Call<TeamModel>
}
TeamPresenter
interface MatchPresenter {
fun loadTeamDetail(team_id: String)
}
TeamImpls
class TeamImpls(val teamView: TeamView) : TeamPresenter { override fun loadTeamDetail(team_id: String) { val call = RetrofitConfig().getApi().getTeam(team_id) call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (response.isSuccessful()) { val res = response.body() res?.let { teamView.onSuccess(it) } } } override fun onFailure(call: Call, t: Throwable) { Log.e("PrevMatchFragment", t.toString()) } }) } }
TeamModel
data class TeamModel( val teams: ArrayList ) data class TeamModeLResult( val idTeam: String, val strTeam: String, val strAlternate: String, val strSport: String, val strStadium: String, val strTeamBadge: String )
And
This my TeamImplsTest
class TeamImplsTest { @Mock private lateinit var teamView: TeamView @Mock private lateinit var teamPresenter: TeamPresenter @Before fun setUp() { MockitoAnnotations.initMocks(this) teamPresenter = TeamImpls(teamView) } @Test fun loadTeamDetail() { val teams = TeamModel(arrayListOf()) val teamId = "133613" teamPresenter.loadTeamDetail(teamId) Mockito.verify(teamView).onSuccess(teams) } }
i got error
Wanted but not invoked: teamView.onSuccess(TeamModel(teams=[])); -> at com.fathurradhy.matchschedule.domain.presenter.TeamImplsTest.loadTeamDetail(TeamImplsTest.kt:34) Actually, there were zero interactions with this mock. Wanted but not invoked: teamView.onSuccess(TeamModel(teams=[])); -> at com.fathurradhy.matchschedule.domain.presenter.TeamImplsTest.loadTeamDetail(TeamImplsTest.kt:34) Actually, there were zero interactions with this mock.