Skip to content

Commit

Permalink
Unit tested the UserAgendaRepo for Droidcon-Boston#138.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 committed Feb 2, 2019
1 parent 1d0d1d0 commit 99ef818
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Droidcon-Boston/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ android {
versionCode 17
versionName "2.0.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true

vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -97,8 +98,10 @@ dependencies {
final flexibleAdapter = '5.0.1'
final flexibleAdapterUi = '1.0.0-b3'
final glide = '3.7.0'
final threeTen = '1.3.3'
final threeTenAbp = '1.0.5'
final recyclerRefreshLayout = '2.0.5'
final mockitoCore = '2.23.4'
//endregion

//region Dependencies
Expand All @@ -107,7 +110,8 @@ dependencies {

// TESTING
testImplementation "junit:junit:$junit"
testImplementation "org.threeten:threetenbp:1.3.3"
testImplementation "org.threeten:threetenbp:$threeTen"
testImplementation "org.mockito:mockito-core:$mockitoCore"

// Support
implementation "androidx.appcompat:appcompat:$appCompat"
Expand Down
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))
}
}

0 comments on commit 99ef818

Please sign in to comment.