-
Notifications
You must be signed in to change notification settings - Fork 175
Fix and add favorite unit test #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
c379df5
2b7785c
fa99dae
f1f2a4a
5b54823
cf3d02c
961d356
fb2b596
b141372
62954b3
0ad9876
0099657
91dad10
1d2374d
a7e6586
d2edebb
5e8fcba
0ccbc1d
076ef28
e208424
bb80b06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,13 @@ import com.dicoding.academies.data.AcademyRepository | |
| import com.dicoding.academies.data.source.local.entity.CourseWithModule | ||
| import com.dicoding.academies.utils.DataDummy | ||
| import com.dicoding.academies.vo.Resource | ||
| import com.nhaarman.mockitokotlin2.doNothing | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.mockito.Mock | ||
| import org.mockito.Mockito | ||
| import org.mockito.Mockito.`when` | ||
| import org.mockito.Mockito.verify | ||
| import org.mockito.junit.MockitoJUnitRunner | ||
|
|
@@ -49,4 +51,22 @@ class DetailCourseViewModelTest { | |
|
|
||
| verify(observer).onChanged(dummyCourseWithModule) | ||
| } | ||
|
|
||
| @Test | ||
| fun setBookmark() { | ||
| val dummyCourseWithModule = Resource.success(DataDummy.generateDummyCourseWithModules(dummyCourse, false)) | ||
| val course = MutableLiveData<Resource<CourseWithModule>>() | ||
| course.value = dummyCourseWithModule | ||
|
|
||
| `when`(academyRepository.getCourseWithModules(courseId)).thenReturn(course) | ||
| viewModel.courseModule.observeForever(observer) | ||
|
|
||
| val courseFromViewModel = viewModel.courseModule.value!!.data | ||
|
||
|
|
||
| doNothing().`when`(academyRepository).setCourseBookmark(courseFromViewModel!!.mCourse, true) | ||
|
||
|
|
||
| viewModel.setBookmark() | ||
|
|
||
| verify(academyRepository).setCourseBookmark(dummyCourse, true) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini dummy cuman buat invoke sama verify? Tambahkan assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kalau yang ini kan yang di test method void dan hanya meneruskan call saja ke repository. Jadi menurutku, disini cukup verify call method saja
https://blog.knoldus.com/unit-testing-void-methods-with-mockito-and-junit/Atau mungkin dari mas Alfian ada cara lain kah ?