-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from snuhcs-course/test/managers
Managers 테스트 구현
- Loading branch information
Showing
4 changed files
with
398 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
frontend/app/src/androidTest/java/com/example/speechbuddy/AuthTokenPrefsManagerTest.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,70 @@ | ||
package com.example.speechbuddy | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.example.speechbuddy.data.local.AuthTokenPrefsManager | ||
import com.example.speechbuddy.domain.models.AuthToken | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class AuthTokenPrefsManagerTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var authTokenPrefsManager: AuthTokenPrefsManager | ||
|
||
private val testAuthToken = AuthToken("testAccessToken", "testRefreshToken") | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext<Context>() | ||
authTokenPrefsManager = AuthTokenPrefsManager(context) | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
runBlocking { | ||
authTokenPrefsManager.clearAuthToken() | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_and_retrieve_auth_token() { | ||
runBlocking { | ||
authTokenPrefsManager.saveAuthToken(testAuthToken) | ||
val observedAuthToken = authTokenPrefsManager.preferencesFlow.first() | ||
assertEquals(testAuthToken, observedAuthToken) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_clear_auth_token() { | ||
runBlocking { | ||
authTokenPrefsManager.clearAuthToken() | ||
|
||
val observedAuthToken = authTokenPrefsManager.preferencesFlow.first() | ||
val expectedAuthToken = AuthToken("", "") | ||
assertEquals(expectedAuthToken, observedAuthToken) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_reset_auth_token_on_clear() { | ||
runBlocking { | ||
val newAuthToken = AuthToken("newAccessToken", "newRefreshToken") | ||
authTokenPrefsManager.saveAuthToken(newAuthToken) | ||
|
||
authTokenPrefsManager.clearAuthToken() | ||
|
||
val observedAuthToken = authTokenPrefsManager.preferencesFlow.first() | ||
val expectedAuthToken = AuthToken("", "") | ||
assertEquals(expectedAuthToken, observedAuthToken) | ||
} | ||
} | ||
} |
150 changes: 150 additions & 0 deletions
150
frontend/app/src/androidTest/java/com/example/speechbuddy/SettingsPrefsManagerTest.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,150 @@ | ||
package com.example.speechbuddy | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.example.speechbuddy.data.local.SettingsPrefsManager | ||
import com.example.speechbuddy.domain.models.SettingsPreferences | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class SettingsPrefsManagerTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var settingsPrefsManager: SettingsPrefsManager | ||
|
||
private val testSettings = SettingsPreferences( | ||
autoBackup = false, | ||
darkMode = true, | ||
initialPage = false, | ||
lastBackupDate = "2023-01-01" | ||
) | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext<Context>() | ||
settingsPrefsManager = SettingsPrefsManager(context) | ||
|
||
runBlocking { | ||
settingsPrefsManager.saveAutoBackup(testSettings.autoBackup) | ||
settingsPrefsManager.saveDarkMode(testSettings.darkMode) | ||
settingsPrefsManager.saveInitialPage(testSettings.initialPage) | ||
settingsPrefsManager.saveLastBackupDate(testSettings.lastBackupDate) | ||
} | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
runBlocking { | ||
settingsPrefsManager.resetSettings() | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_and_retrieve_settings() { | ||
runBlocking { | ||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
assertEquals(testSettings, observedSettings) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_auto_backup_setting() { | ||
runBlocking { | ||
val testAutoBackupValue = true | ||
settingsPrefsManager.saveAutoBackup(testAutoBackupValue) | ||
|
||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
|
||
val expectedSettings = SettingsPreferences( | ||
autoBackup = testAutoBackupValue, | ||
darkMode = true, | ||
initialPage = false, | ||
lastBackupDate = "2023-01-01" | ||
) | ||
assertEquals(expectedSettings, observedSettings) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_dark_mode_setting() { | ||
runBlocking { | ||
val testDarkModeValue = false | ||
settingsPrefsManager.saveDarkMode(testDarkModeValue) | ||
|
||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
|
||
val expectedSettings = SettingsPreferences( | ||
autoBackup = false, | ||
darkMode = testDarkModeValue, | ||
initialPage = false, | ||
lastBackupDate = "2023-01-01" | ||
) | ||
assertEquals(expectedSettings, observedSettings) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_initial_page_setting() { | ||
runBlocking { | ||
val testInitialPageValue = true | ||
settingsPrefsManager.saveInitialPage(testInitialPageValue) | ||
|
||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
|
||
val expectedSettings = SettingsPreferences( | ||
autoBackup = false, | ||
darkMode = true, | ||
initialPage = testInitialPageValue, | ||
lastBackupDate = "2023-01-01" | ||
) | ||
assertEquals(expectedSettings, observedSettings) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_last_backup_date_setting() { | ||
runBlocking { | ||
val testLastBackupDateValue = "2023-02-15" | ||
settingsPrefsManager.saveLastBackupDate(testLastBackupDateValue) | ||
|
||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
|
||
val expectedSettings = SettingsPreferences( | ||
autoBackup = false, | ||
darkMode = true, | ||
initialPage = false, | ||
lastBackupDate = testLastBackupDateValue | ||
) | ||
assertEquals(expectedSettings, observedSettings) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_reset_settings() { | ||
runBlocking { | ||
// Set some non-default values first | ||
settingsPrefsManager.saveAutoBackup(false) | ||
settingsPrefsManager.saveDarkMode(true) | ||
settingsPrefsManager.saveInitialPage(false) | ||
settingsPrefsManager.saveLastBackupDate("2023-01-01") | ||
|
||
settingsPrefsManager.resetSettings() | ||
|
||
val observedSettings = settingsPrefsManager.settingsPreferencesFlow.first() | ||
val defaultSettings = SettingsPreferences( | ||
autoBackup = true, | ||
darkMode = false, | ||
initialPage = true, | ||
lastBackupDate = "" | ||
) | ||
assertEquals(defaultSettings, observedSettings) | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
frontend/app/src/androidTest/java/com/example/speechbuddy/UserIdPrefsManagerTest.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,58 @@ | ||
package com.example.speechbuddy | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.example.speechbuddy.data.local.UserIdPrefsManager | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class UserIdPrefsManagerTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var userIdPrefsManager: UserIdPrefsManager | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext<Context>() | ||
userIdPrefsManager = UserIdPrefsManager(context) | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
runBlocking { | ||
userIdPrefsManager.clearUserId() | ||
} | ||
} | ||
|
||
@Test | ||
fun should_save_user_id() { | ||
runBlocking { | ||
userIdPrefsManager.saveUserId(USER_ID_VALUE) | ||
|
||
val observedUserId = userIdPrefsManager.preferencesFlow.first() | ||
assertEquals(USER_ID_VALUE, observedUserId) | ||
} | ||
} | ||
|
||
@Test | ||
fun should_clear_user_id() { | ||
runBlocking { | ||
userIdPrefsManager.saveUserId(USER_ID_VALUE) | ||
|
||
userIdPrefsManager.clearUserId() | ||
val observedUserId = userIdPrefsManager.preferencesFlow.first() | ||
assertEquals(null, observedUserId) | ||
} | ||
} | ||
|
||
companion object { | ||
const val USER_ID_VALUE = 123 | ||
} | ||
} |
Oops, something went wrong.