forked from Droidcon-Boston/conference-app-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tested the UserAgendaRepo for Droidcon-Boston#138.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
...on-Boston/app/src/test/java/com/mentalmachines/droidcon_boston/data/UserAgendaRepoTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mentalmachines.droidcon_boston.data | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import org.junit.Assert.* | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.ArgumentMatchers.* | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.mock | ||
|
||
class UserAgendaRepoTest { | ||
private val mockSharedPrefs = mock(SharedPreferences::class.java) | ||
private val mockEditor = mock(SharedPreferences.Editor::class.java) | ||
private val mockContext = mock(Context::class.java) | ||
private lateinit var userAgendaRepo: UserAgendaRepo | ||
|
||
@Before | ||
fun setup() { | ||
`when`(mockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(mockSharedPrefs) | ||
`when`(mockSharedPrefs.edit()).thenReturn(mockEditor) | ||
`when`(mockEditor.putStringSet(anyString(), any())).thenReturn(mockEditor) | ||
userAgendaRepo = UserAgendaRepo.getInstance(mockContext) | ||
} | ||
|
||
@Test | ||
fun testBookmarkAndRemove() { | ||
val sessionId = "Session ID" | ||
assertFalse(userAgendaRepo.isSessionBookmarked(sessionId)) | ||
|
||
userAgendaRepo.bookmarkSession(sessionId, true) | ||
assertTrue(userAgendaRepo.isSessionBookmarked(sessionId)) | ||
|
||
userAgendaRepo.bookmarkSession(sessionId, false) | ||
assertFalse(userAgendaRepo.isSessionBookmarked(sessionId)) | ||
} | ||
} |