11package com.digiventure.ventnote.data.google_drive
22
3+ import android.app.Application
34import com.digiventure.utils.BaseUnitTest
45import com.digiventure.ventnote.data.persistence.NoteDAO
56import com.digiventure.ventnote.data.persistence.NoteModel
7+ import com.digiventure.ventnote.feature.widget.WidgetRefresher
68import com.digiventure.ventnote.module.proxy.DatabaseProxy
79import com.google.api.services.drive.Drive
810import com.google.api.services.drive.model.File
@@ -20,8 +22,10 @@ import org.mockito.kotlin.verify
2022import org.mockito.kotlin.whenever
2123
2224class GoogleDriveServiceShould : BaseUnitTest () {
25+ private val app: Application = mock()
2326 private val proxy: DatabaseProxy = mock()
2427 private val dao: NoteDAO = mock()
28+ private val refresher: WidgetRefresher = mock()
2529 private val noteList: List <NoteModel > = listOf ()
2630 private val fileName: String = " backup.json"
2731 private val fileId: String = " 1"
@@ -31,7 +35,7 @@ class GoogleDriveServiceShould: BaseUnitTest() {
3135
3236 @Before
3337 fun setup () {
34- service = GoogleDriveService (proxy)
38+ service = GoogleDriveService (app, proxy, refresher )
3539 }
3640
3741 @Test
@@ -72,13 +76,14 @@ class GoogleDriveServiceShould: BaseUnitTest() {
7276 whenever(drive.files()).thenReturn(filesMock)
7377 whenever(filesMock.get(fileId)).thenReturn(getMock)
7478 whenever(getMock.executeMediaAsInputStream()).thenReturn(inputStream)
75- whenever(dao.upsertNotesWithTimestamp (any())).thenAnswer { }
79+ whenever(dao.upsertNotes (any())).thenAnswer { }
7680 whenever(proxy.dao()).thenReturn(dao)
7781
7882 val result = service.readFile(fileId, drive)
7983
8084 assertTrue(result.isSuccess)
81- verify(proxy.dao(), times(1 )).upsertNotesWithTimestamp(any())
85+ verify(proxy.dao(), times(1 )).upsertNotes(any())
86+ verify(refresher, times(1 )).refresh(app)
8287 }
8388
8489 @Test
@@ -103,7 +108,7 @@ class GoogleDriveServiceShould: BaseUnitTest() {
103108 whenever(drive.files()).thenReturn(filesMock)
104109 whenever(filesMock.get(fileId)).thenReturn(getMock)
105110 whenever(getMock.executeMediaAsInputStream()).thenReturn(inputStream)
106- whenever(dao.upsertNotesWithTimestamp (any())).thenAnswer {
111+ whenever(dao.upsertNotes (any())).thenAnswer {
107112 throw exception
108113 }
109114 whenever(proxy.dao()).thenReturn(dao)
0 commit comments