From c119dc1ccca0904ed9b8a59bd6a9c09abac58b14 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:37:34 +0200 Subject: [PATCH 01/22] TypinGame: inject UserRepo --- .../activity/GameSetupActivityTest.kt | 9 ++++- .../activity/TypingGameActivityTest.kt | 35 +++++++++++++++---- .../vibester/activity/TypingGameActivity.kt | 10 ++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt index 850b0c381..042dc6e1e 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt @@ -16,6 +16,8 @@ import androidx.test.espresso.matcher.ViewMatchers.withSpinnerText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.sdp.vibester.R +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest import org.hamcrest.Matchers import org.junit.After import org.junit.Before @@ -24,13 +26,18 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) +@HiltAndroidTest class GameSetupActivityTest { - @get: Rule + @get:Rule(order = 0) + var hiltRule = HiltAndroidRule(this) + + @get: Rule(order = 1) val activityRule = ActivityScenarioRule(GameSetupActivity::class.java) @Before fun setUp() { + hiltRule.inject() Intents.init() } diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt index 3065522af..7c239fb3b 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt @@ -18,10 +18,15 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.sdp.vibester.R -import ch.sdp.vibester.TestMode import ch.sdp.vibester.api.LastfmMethod +import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.helper.TypingGameManager import ch.sdp.vibester.model.Song +import dagger.hilt.android.testing.BindValue +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import io.mockk.every +import io.mockk.mockk import org.junit.After import org.junit.Assert.assertEquals import org.junit.Before @@ -30,14 +35,18 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) +@HiltAndroidTest class TypingGameActivityTest { - @JvmField - @get:Rule + @get:Rule(order = 0) + var hiltRule = HiltAndroidRule(this) + + @get:Rule(order = 1) val activityRule = ActivityScenarioRule(TypingGameActivity::class.java) @Before fun setUp() { + hiltRule.inject() Intents.init() } @@ -46,6 +55,17 @@ class TypingGameActivityTest { Intents.release() } + @BindValue + @JvmField + val mockUsersRepo = mockk() + + private fun createMockInvocation() { + every {mockUsersRepo.updateBestFieldInt(any(), any(), any())} answers {} + every {mockUsersRepo.updateRelativeFieldInt(any(), any(), any())} answers {} + every {mockUsersRepo.updateFieldInt(any(), any(), any())} answers {} + + } + private val expectedSize = 200 private fun setGameManager(numSongs:Int = 1, valid: Boolean = true): TypingGameManager { val epilogue = "{\"tracks\":{\"track\":[" @@ -110,7 +130,7 @@ class TypingGameActivityTest { @Test fun guessLayoutTest() { - TestMode.setTest() + createMockInvocation() val inputTxt = """ { "resultCount":1, @@ -163,6 +183,7 @@ class TypingGameActivityTest { // Do not put gameManager as an extra val scn: ActivityScenario = ActivityScenario.launch(intent) val ctx = ApplicationProvider.getApplicationContext() as Context + createMockInvocation() scn.onActivity { activity -> activity.checkAnswer(ctx, songTest, gameManager) } @@ -188,6 +209,7 @@ class TypingGameActivityTest { Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java) val scn: ActivityScenario = ActivityScenario.launch(intent) val ctx = ApplicationProvider.getApplicationContext() as Context + createMockInvocation() scn.onActivity { activity -> activity.checkAnswer(ctx, songTest, gameManager) } @@ -201,7 +223,7 @@ class TypingGameActivityTest { */ @Test fun checkIntentOnEnding() { - TestMode.setTest() + createMockInvocation() val inputTxt = """ { "resultCount":1, @@ -249,6 +271,7 @@ class TypingGameActivityTest { val intent = Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java) val scn: ActivityScenario = ActivityScenario.launch(intent) val ctx = ApplicationProvider.getApplicationContext() as Context + createMockInvocation() scn.onActivity { activity -> activity.testFirstRound(ctx, gameManager) activity.testProgressBar() @@ -276,7 +299,7 @@ class TypingGameActivityTest { @Test fun nextButtonOnClick(){ - TestMode.setTest() + createMockInvocation() val gameManager = setGameManager(2) assertEquals(gameManager.getSongList().size, 2) diff --git a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt index c1f6ac45e..fb9caa328 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt @@ -17,20 +17,25 @@ import ch.sdp.vibester.helper.DisplayContents import ch.sdp.vibester.helper.GameManager import ch.sdp.vibester.helper.TypingGameManager import ch.sdp.vibester.model.Song +import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.launch import okhttp3.OkHttpClient +import javax.inject.Inject /** * Class that represent a game */ - +@AndroidEntryPoint class TypingGameActivity : GameActivity() { private lateinit var gameManager: TypingGameManager private var gameIsOn: Boolean = true // done to avoid clicks on songs after the round is over + @Inject + lateinit var dataGetter: DataGetter + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE) @@ -212,8 +217,7 @@ class TypingGameActivity : GameActivity() { toggleNextBtnVisibility(true) // If currently not in test and has finished the game, update the scores - if (isEndGame(gameManager) && !TestMode.isTest()) { - val dataGetter = DataGetter() + if (isEndGame(gameManager)) { dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), 1, "totalGames") dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getCorrectSongs().size, "correctSongs") dataGetter.updateBestFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "bestScore") From 4db7d6ea91bfdfef6d73cc5c3794dee9fed91be5 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:37:50 +0200 Subject: [PATCH 02/22] TypinGameActivity: set score per each game --- .../main/java/ch/sdp/vibester/activity/TypingGameActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt index fb9caa328..e5d98d0c5 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt @@ -221,7 +221,7 @@ class TypingGameActivity : GameActivity() { dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), 1, "totalGames") dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getCorrectSongs().size, "correctSongs") dataGetter.updateBestFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "bestScore") - + dataGetter.updateBestSubFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "scores", gameManager.gameMode) } } From 62077ba2e42241da0e9d3d3cb620c3d16988a977 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:38:14 +0200 Subject: [PATCH 03/22] GameManager: set mode for the game --- .../ch/sdp/vibester/activity/GameSetupActivity.kt | 14 ++++++++------ .../java/ch/sdp/vibester/helper/GameManager.kt | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt index ee8ba0183..143b72764 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt @@ -142,14 +142,15 @@ class GameSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListene var method = "" var artist = "" var tag = "" + var mode = "" val uri = LastfmUri() when (view.id) { - R.id.btsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "BTS" } - R.id.kpopButton -> {method = LastfmMethod.BY_TAG.method; tag = "kpop" } - R.id.imagDragonsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Imagine Dragons"} - R.id.rockButton-> {method = LastfmMethod.BY_TAG.method; tag = "rock" } - R.id.topTracksButton -> {method = LastfmMethod.BY_CHART.method} - R.id.billieEilishButton -> {method =LastfmMethod.BY_ARTIST.method; artist = "Billie Eilish"} + R.id.btsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "BTS"; mode = "BTS" } + R.id.kpopButton -> {method = LastfmMethod.BY_TAG.method; tag = "kpop"; mode = "kpop" } + R.id.imagDragonsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Imagine Dragons"; mode = "Imagine Dragons"} + R.id.rockButton-> {method = LastfmMethod.BY_TAG.method; tag = "rock"; mode = "rock" } + R.id.topTracksButton -> {method = LastfmMethod.BY_CHART.method; mode = "top tracks"} + R.id.billieEilishButton -> {method =LastfmMethod.BY_ARTIST.method; artist = "Billie Eilish"; mode = "billie eilish"} } uri.method = method uri.artist = artist @@ -158,6 +159,7 @@ class GameSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListene findViewById(R.id.chooseGenre).visibility = GONE findViewById(R.id.chooseDifficulty).visibility = VISIBLE + gameManager.gameMode = mode setGameSongList(uri) } diff --git a/app/src/main/java/ch/sdp/vibester/helper/GameManager.kt b/app/src/main/java/ch/sdp/vibester/helper/GameManager.kt index c16c2a242..21026448f 100644 --- a/app/src/main/java/ch/sdp/vibester/helper/GameManager.kt +++ b/app/src/main/java/ch/sdp/vibester/helper/GameManager.kt @@ -13,6 +13,7 @@ open class GameManager : Serializable { private var score = 0 open var gameSize = 5 var numPlayedSongs = 0 + var gameMode = "" open lateinit var currentSong: Song var gameSongList: MutableList> = mutableListOf() private val correctSongs = mutableListOf() //TODO: question: why this is a val but the next one is a var? From 8dc937fa7c16de615f2175b521cd372bd781684d Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:40:41 +0200 Subject: [PATCH 04/22] DataGetter: simplify docymentation --- .../ch/sdp/vibester/database/DataGetter.kt | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 5de362094..db5c17734 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -25,8 +25,8 @@ class DataGetter @Inject constructor() { /** * This function updates a specific string field of a user in the database * @param userID the id of the user which is being updated - * @param newVal (String) the new value of the field that is being updated - * @param fieldName the field name of the field that is being updated + * @param newVal integer value to update + * @param fieldName field name to updated */ fun updateFieldString(userID: String, newVal: String, fieldName: String) { dbUserRef.child(userID) @@ -36,9 +36,9 @@ class DataGetter @Inject constructor() { /** * This function updates a specific int field of a user in the database - * @param userID the id of the user which is being updated - * @param newVal (Int) the new value of the field that is being updated - * @param fieldName the field name of the field that is being updated + * @param userID + * @param newVal integer value to update + * @param fieldName field name to updated */ fun updateFieldInt(userID: String, newVal: Int, fieldName: String) { dbUserRef.child(userID) @@ -49,9 +49,9 @@ class DataGetter @Inject constructor() { /** * This function increments a specific int field of a user in the database - * @param userID the id of the user which is being updated - * @param newVal (Int) the increment value of the field that is being updated - * @param fieldName the field name of the field that is being updated + * @param userID + * @param newVal integer value to update + * @param fieldName field name to updated */ fun updateRelativeFieldInt(userID: String, newVal: Int, fieldName: String) { if(!TestMode.isTest()) { @@ -81,6 +81,15 @@ class DataGetter @Inject constructor() { } } + /** + * Update the best value of subfield + * @param userID + * @param newVal integer value to update + * @param fieldName field name to updated + * @param subFieldName subfield name to updated + */ + } + /** * Update a subfield of user's field From a8792aa71f125a35a45e1379b7418e74bc11618d Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:40:56 +0200 Subject: [PATCH 05/22] DataGetter: fix the function to set relative integer field --- .../java/ch/sdp/vibester/database/DataGetter.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index db5c17734..45f1cdcff 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -54,14 +54,13 @@ class DataGetter @Inject constructor() { * @param fieldName field name to updated */ fun updateRelativeFieldInt(userID: String, newVal: Int, fieldName: String) { - if(!TestMode.isTest()) { - dbUserRef.child(userID).child(fieldName) - .get().addOnSuccessListener { t -> - if(!TestMode.isTest()) { - updateFieldInt(userID, (t.value as Long?)!!.toInt() + newVal, fieldName) - } - } - } + dbUserRef.child(userID).child(fieldName) + .get().addOnSuccessListener { t -> + var sum = newVal + if(t.value != null){sum += (t.value as Long?)!!.toInt()} + updateFieldInt(userID, sum, fieldName) + } + } /** From 74a9553f7d45a34551c98613cfa824a35fa4b3ee Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:41:17 +0200 Subject: [PATCH 06/22] DataGetter: fix the function updateBestFIeldInt --- .../java/ch/sdp/vibester/database/DataGetter.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 45f1cdcff..726ae23ec 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -68,16 +68,16 @@ class DataGetter @Inject constructor() { * @param userID the id of the user which is being updated * @param newVal (Int) the new value of the field that is being compared and updated * @param fieldName the field name of the field that is being updated + * @param newVal integer value to update + * @param fieldName field name to updated */ fun updateBestFieldInt(userID: String, newVal: Int, fieldName: String) { - if(!TestMode.isTest()) { - dbUserRef.child(userID).child(fieldName) - .get().addOnSuccessListener { t -> - if(!TestMode.isTest()) { - updateFieldInt(userID, maxOf((t.value as Long?)!!.toInt(), newVal), fieldName) - } + dbUserRef.child(userID).child(fieldName) + .get().addOnSuccessListener { t -> + var maxValue = newVal + if(t.value != null){maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} + updateFieldInt(userID, maxValue, fieldName) } - } } /** From 1e2058f6edbdf1708768212f13eb46310f728676 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:41:45 +0200 Subject: [PATCH 07/22] DataGetter: new funciton updateBestSubFieldInt --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 726ae23ec..724047991 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -87,6 +87,13 @@ class DataGetter @Inject constructor() { * @param fieldName field name to updated * @param subFieldName subfield name to updated */ + fun updateBestSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String) { + dbUserRef.child(userID).child(fieldName).child(subFieldName) + .get().addOnSuccessListener { t -> + var maxValue = newVal + if(t.value != null){maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} + updateFieldSubFieldInt(userID, maxValue, fieldName, subFieldName) + } } From 4bc6094063f119fd25cef1b37684c16959e2576a Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:41:56 +0200 Subject: [PATCH 08/22] DataGetter: update the comment --- .../main/java/ch/sdp/vibester/database/DataGetter.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 724047991..a1027a07d 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -98,11 +98,11 @@ class DataGetter @Inject constructor() { /** - * Update a subfield of user's field - * @param userID the id of the user which is being updated - * @param newVal (Boolean) the new value of the field that is being updated - * @param fieldName the field name of the field that is being updated - * @param subFieldName the field name of the field that is being updated + * Update Boolean subfield of user's field + * @param userID + * @param newVal integer value to update + * @param fieldName field name to updated + * @param subFieldName subfield name to updated */ fun updateFieldSubFieldBoolean(userID: String, newVal: Boolean, fieldName: String, subFieldName: String) { dbUserRef.child(userID) From 75148924bf0994a3221ab2b68288109af752c089 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:42:22 +0200 Subject: [PATCH 09/22] DataGetter: new FieldSubFieldInt --- .../java/ch/sdp/vibester/database/DataGetter.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index a1027a07d..3a4dec093 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -111,6 +111,20 @@ class DataGetter @Inject constructor() { .setValue(newVal) } + /** + * Update Integer subfield of user's field + * @param userID + * @param newVal integer value to update + * @param fieldName field name to updated + * @param subFieldName subfield name to updated + */ + fun updateFieldSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String) { + dbUserRef.child(userID) + .child(fieldName) + .child(subFieldName) + .setValue(newVal) + } + /** * This function creates a new user account in the database * @param email the email of the new user From 161fd802ff2be0b15b76ab3e5d460ed5a80df1a3 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sat, 30 Apr 2022 23:42:39 +0200 Subject: [PATCH 10/22] DataGetter: fix the documentation --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 3a4dec093..ea80e4ad3 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -66,8 +66,6 @@ class DataGetter @Inject constructor() { /** * This function sets the best between current and given in argument value * @param userID the id of the user which is being updated - * @param newVal (Int) the new value of the field that is being compared and updated - * @param fieldName the field name of the field that is being updated * @param newVal integer value to update * @param fieldName field name to updated */ From fd43f16182a029736bfd874cb4ed6d58b1200b03 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sun, 1 May 2022 13:39:14 +0200 Subject: [PATCH 11/22] TypingGameActivity: fix the mocking --- .../java/ch/sdp/vibester/activity/TypingGameActivityTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt index 7c239fb3b..3a72df3f4 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt @@ -63,6 +63,8 @@ class TypingGameActivityTest { every {mockUsersRepo.updateBestFieldInt(any(), any(), any())} answers {} every {mockUsersRepo.updateRelativeFieldInt(any(), any(), any())} answers {} every {mockUsersRepo.updateFieldInt(any(), any(), any())} answers {} + every {mockUsersRepo.updateBestSubFieldInt(any(), any(), any(), any())} answers {} + } From 63c17230115f0d5232250f2218a77ecc1069e00d Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Sun, 1 May 2022 19:42:44 +0200 Subject: [PATCH 12/22] Update app/src/main/java/ch/sdp/vibester/database/DataGetter.kt Co-authored-by: jiabaow <60721007+jiabaow@users.noreply.github.com> --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index ea80e4ad3..7b893e2d3 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -89,7 +89,7 @@ class DataGetter @Inject constructor() { dbUserRef.child(userID).child(fieldName).child(subFieldName) .get().addOnSuccessListener { t -> var maxValue = newVal - if(t.value != null){maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} + if(t.value != null) {maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} updateFieldSubFieldInt(userID, maxValue, fieldName, subFieldName) } } From 10a2874c8cfb20275d605fd4465d5136471528fd Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Sun, 1 May 2022 19:42:48 +0200 Subject: [PATCH 13/22] Update app/src/main/java/ch/sdp/vibester/database/DataGetter.kt Co-authored-by: jiabaow <60721007+jiabaow@users.noreply.github.com> --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 7b893e2d3..b2b7e5b5f 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -73,7 +73,7 @@ class DataGetter @Inject constructor() { dbUserRef.child(userID).child(fieldName) .get().addOnSuccessListener { t -> var maxValue = newVal - if(t.value != null){maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} + if(t.value != null) {maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} updateFieldInt(userID, maxValue, fieldName) } } From 951d64516a898d73e9ed63ac203c3b86b4ef005f Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Sun, 1 May 2022 19:42:51 +0200 Subject: [PATCH 14/22] Update app/src/main/java/ch/sdp/vibester/database/DataGetter.kt Co-authored-by: jiabaow <60721007+jiabaow@users.noreply.github.com> --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index b2b7e5b5f..264506692 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -57,7 +57,7 @@ class DataGetter @Inject constructor() { dbUserRef.child(userID).child(fieldName) .get().addOnSuccessListener { t -> var sum = newVal - if(t.value != null){sum += (t.value as Long?)!!.toInt()} + if(t.value != null) {sum += (t.value as Long?)!!.toInt()} updateFieldInt(userID, sum, fieldName) } From c5b27dd689e5662552df2605d5e62b411ead60f3 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Sun, 1 May 2022 22:12:04 +0200 Subject: [PATCH 15/22] modify database calls and change appropriately in the code --- .../vibester/activity/ProfileActivityTest.kt | 2 +- .../activity/TypingGameActivityTest.kt | 10 +- .../activity/CreateProfileActivity.kt | 2 +- .../sdp/vibester/activity/ProfileActivity.kt | 2 +- .../vibester/activity/TypingGameActivity.kt | 8 +- .../ch/sdp/vibester/database/DataGetter.kt | 114 +++++++----------- .../sdp/vibester/user/UserProfileAdapter.kt | 2 +- 7 files changed, 54 insertions(+), 86 deletions(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt index e7a6d8c7c..df5f47c87 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt @@ -49,7 +49,7 @@ class ProfileActivityTest { every { mockUsersRepo.getUserData(any()) } answers { secondArg<(User) -> Unit>().invoke(mockProfile) } - every { mockUsersRepo.updateFieldString(any(), any(), any()) } answers {} + every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} every { mockUsersRepo.getUserData(any())} answers {} } diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt index 3a72df3f4..1815430f7 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt @@ -60,12 +60,10 @@ class TypingGameActivityTest { val mockUsersRepo = mockk() private fun createMockInvocation() { - every {mockUsersRepo.updateBestFieldInt(any(), any(), any())} answers {} - every {mockUsersRepo.updateRelativeFieldInt(any(), any(), any())} answers {} - every {mockUsersRepo.updateFieldInt(any(), any(), any())} answers {} - every {mockUsersRepo.updateBestSubFieldInt(any(), any(), any(), any())} answers {} - - + every {mockUsersRepo.setSubFieldValue(any(), any(), any(),any())} answers {} + every {mockUsersRepo.updateFieldInt(any(), any(), any(), any())} answers {} + every {mockUsersRepo.setFieldValue(any(), any(), any())} answers {} + every {mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(), any())} answers {} } private val expectedSize = 200 diff --git a/app/src/main/java/ch/sdp/vibester/activity/CreateProfileActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/CreateProfileActivity.kt index 2f0ca72cc..f668a35aa 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/CreateProfileActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/CreateProfileActivity.kt @@ -42,7 +42,7 @@ class CreateProfileActivity : AppCompatActivity() { btCreateAcc.setOnClickListener { if (!TestMode.isTest()){ - dataGetter.updateFieldString(FireBaseAuthenticator.getCurrentUID(), username.text.toString(), "username") + dataGetter.setFieldValue(FireBaseAuthenticator.getCurrentUID(), "username", username.text.toString()) } startNewActivity(email) } diff --git a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt index 303b81256..41402ebc1 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt @@ -101,7 +101,7 @@ class ProfileActivity : AppCompatActivity() { findViewById(textId).text = input.text.toString() if(name == "username"){ - dataGetter.updateFieldString(FireBaseAuthenticator.getCurrentUID(), input.text.toString(), "username") + dataGetter.setFieldValue(FireBaseAuthenticator.getCurrentUID(),"username", input.text.toString()) } } diff --git a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt index e5d98d0c5..289444590 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt @@ -218,10 +218,10 @@ class TypingGameActivity : GameActivity() { // If currently not in test and has finished the game, update the scores if (isEndGame(gameManager)) { - dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), 1, "totalGames") - dataGetter.updateRelativeFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getCorrectSongs().size, "correctSongs") - dataGetter.updateBestFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "bestScore") - dataGetter.updateBestSubFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "scores", gameManager.gameMode) + dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "totalGames", 1, method = "sum") + dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "correctSongs", gameManager.getCorrectSongs().size, method = "sum") + dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "bestScore", gameManager.getScore(), method = "best") + dataGetter.updateSubFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "scores", gameManager.gameMode, method = "best") } } diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 264506692..3d7d0d3d5 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -21,108 +21,78 @@ class DataGetter @Inject constructor() { private val dbRoomRef = Database.get().getReference("rooms") private val authenticator: FireBaseAuthenticator = FireBaseAuthenticator() - /** - * This function updates a specific string field of a user in the database - * @param userID the id of the user which is being updated - * @param newVal integer value to update - * @param fieldName field name to updated + * Set field value + * @param uid user identifier + * @param newVal new value to set + * @param fieldName */ - fun updateFieldString(userID: String, newVal: String, fieldName: String) { - dbUserRef.child(userID) + fun setFieldValue(uid: String, fieldName: String, newVal: Any) { + dbUserRef.child(uid) .child(fieldName) .setValue(newVal) } /** - * This function updates a specific int field of a user in the database - * @param userID - * @param newVal integer value to update - * @param fieldName field name to updated + * Set subfield value + * @param uid user identifier + * @param newVal new value to set + * @param fieldName + * @param subFieldName */ - fun updateFieldInt(userID: String, newVal: Int, fieldName: String) { - dbUserRef.child(userID) + fun setSubFieldValue(uid: String, fieldName: String, subFieldName: String, newVal: Any) { + dbUserRef.child(uid) .child(fieldName) + .child(subFieldName) .setValue(newVal) } /** - * This function increments a specific int field of a user in the database + * Update integer value in a subfield based on method sum/best * @param userID - * @param newVal integer value to update - * @param fieldName field name to updated + * @param newVal + * @param fieldName */ - fun updateRelativeFieldInt(userID: String, newVal: Int, fieldName: String) { - dbUserRef.child(userID).child(fieldName) + fun updateFieldInt(uid: String, fieldName: String, newVal: Int, method:String) { + dbUserRef.child(uid).child(fieldName) .get().addOnSuccessListener { t -> - var sum = newVal - if(t.value != null) {sum += (t.value as Long?)!!.toInt()} - updateFieldInt(userID, sum, fieldName) + var finalVal = newVal + if(t.value != null) { + val previousVal = (t.value as Long?)!!.toInt() + when (method) { + "sum" -> finalVal += previousVal + "best" -> finalVal = maxOf(previousVal, newVal) + } + } + setFieldValue(uid, fieldName, finalVal) } - } - /** - * This function sets the best between current and given in argument value - * @param userID the id of the user which is being updated - * @param newVal integer value to update - * @param fieldName field name to updated - */ - fun updateBestFieldInt(userID: String, newVal: Int, fieldName: String) { - dbUserRef.child(userID).child(fieldName) - .get().addOnSuccessListener { t -> - var maxValue = newVal - if(t.value != null) {maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} - updateFieldInt(userID, maxValue, fieldName) - } - } /** - * Update the best value of subfield + * Update the integer value of subfield based on method sum/best * @param userID - * @param newVal integer value to update - * @param fieldName field name to updated - * @param subFieldName subfield name to updated + * @param newVal + * @param fieldName + * @param subFieldName */ - fun updateBestSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String) { + fun updateSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String, method: String) { dbUserRef.child(userID).child(fieldName).child(subFieldName) .get().addOnSuccessListener { t -> - var maxValue = newVal - if(t.value != null) {maxValue = maxOf((t.value as Long?)!!.toInt(), newVal)} - updateFieldSubFieldInt(userID, maxValue, fieldName, subFieldName) + var finalVal = newVal + if(t.value != null) { + val previousVal = (t.value as Long?)!!.toInt() + when (method) { + "sum" -> finalVal += previousVal + "best" -> finalVal = maxOf(previousVal, newVal) + } + } + setSubFieldValue(userID, fieldName, subFieldName, finalVal) } } - /** - * Update Boolean subfield of user's field - * @param userID - * @param newVal integer value to update - * @param fieldName field name to updated - * @param subFieldName subfield name to updated - */ - fun updateFieldSubFieldBoolean(userID: String, newVal: Boolean, fieldName: String, subFieldName: String) { - dbUserRef.child(userID) - .child(fieldName) - .child(subFieldName) - .setValue(newVal) - } - - /** - * Update Integer subfield of user's field - * @param userID - * @param newVal integer value to update - * @param fieldName field name to updated - * @param subFieldName subfield name to updated - */ - fun updateFieldSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String) { - dbUserRef.child(userID) - .child(fieldName) - .child(subFieldName) - .setValue(newVal) - } - /** * This function creates a new user account in the database * @param email the email of the new user diff --git a/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt b/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt index dc7087e40..bb0f6e97d 100644 --- a/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt +++ b/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt @@ -55,7 +55,7 @@ class UserProfileAdapter constructor(val users: MutableList): addFriendBtn.setOnClickListener{ val currentUser = authenticator.getCurrUser() if(currentUser != null){ - usersRepo.updateFieldSubFieldBoolean(currentUser!!.uid, true, "friends", user.uid) + usersRepo.setSubFieldValue(currentUser.uid, "friends", user.uid, true) addFriendBtn.visibility = View.INVISIBLE itemView.findViewById(R.id.addedFriendIcon).visibility = View.VISIBLE } From 47f7c18660981a5fa955a0c83f8d063b0803f1f0 Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Mon, 2 May 2022 13:42:39 +0200 Subject: [PATCH 16/22] Update app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt Co-authored-by: Maxime <61186830+MaximeZmt@users.noreply.github.com> --- .../ch/sdp/vibester/activity/TypingGameActivityTest.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt index 1815430f7..754c7c20d 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt @@ -60,10 +60,11 @@ class TypingGameActivityTest { val mockUsersRepo = mockk() private fun createMockInvocation() { - every {mockUsersRepo.setSubFieldValue(any(), any(), any(),any())} answers {} - every {mockUsersRepo.updateFieldInt(any(), any(), any(), any())} answers {} - every {mockUsersRepo.setFieldValue(any(), any(), any())} answers {} - every {mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(), any())} answers {} + every { mockUsersRepo.setSubFieldValue(any(), any(), any(), any()) } answers {} + every { mockUsersRepo.updateFieldInt(any(), any(), any(), any()) } answers {} + every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} + every { mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(), any()) } answers {} + } private val expectedSize = 200 From 92f5f778668fc4c741e514e6e441b351566246ac Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Mon, 2 May 2022 13:42:47 +0200 Subject: [PATCH 17/22] Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt Co-authored-by: Maxime <61186830+MaximeZmt@users.noreply.github.com> --- app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt index 41402ebc1..4bcbd8aa4 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt @@ -101,7 +101,8 @@ class ProfileActivity : AppCompatActivity() { findViewById(textId).text = input.text.toString() if(name == "username"){ - dataGetter.setFieldValue(FireBaseAuthenticator.getCurrentUID(),"username", input.text.toString()) + dataGetter.setFieldValue(FireBaseAuthenticator.getCurrentUID(), "username", input.text.toString()) + } } From 05e1082763bd272a5449cb0fbc3845c9e2dda530 Mon Sep 17 00:00:00 2001 From: kamilababayeva <51053878+kamilababayeva@users.noreply.github.com> Date: Mon, 2 May 2022 13:42:57 +0200 Subject: [PATCH 18/22] Update app/src/main/java/ch/sdp/vibester/database/DataGetter.kt Co-authored-by: Maxime <61186830+MaximeZmt@users.noreply.github.com> --- app/src/main/java/ch/sdp/vibester/database/DataGetter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 3d7d0d3d5..29c7d16dc 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -80,7 +80,7 @@ class DataGetter @Inject constructor() { fun updateSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String, method: String) { dbUserRef.child(userID).child(fieldName).child(subFieldName) .get().addOnSuccessListener { t -> - var finalVal = newVal + var finalVal = newVal if(t.value != null) { val previousVal = (t.value as Long?)!!.toInt() when (method) { From e71d054ee2ca05e52e3ff2bee1c7c97023591ccd Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Mon, 2 May 2022 19:45:16 +0200 Subject: [PATCH 19/22] SearchUserActivity: update score after game --- .../java/ch/sdp/vibester/activity/SearchUserActivityTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt index e4773582b..c5ab03440 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt @@ -62,7 +62,7 @@ class SearchUserActivityTest { secondArg<(User) -> Unit>().invoke(mockUser) } - every {mockUsersRepo.updateFieldSubFieldBoolean(any(), any(), any(), any())} answers {} + every {mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(),any())} answers {} } @BindValue @JvmField From 1c7dce2b2e46afb935800bc0d8913bdaadee95af Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Mon, 2 May 2022 20:47:07 +0200 Subject: [PATCH 20/22] ProfileActivityTest: fix the tests --- .../java/ch/sdp/vibester/activity/ProfileActivityTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt index 1ea1a877d..e9a592f9b 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt @@ -70,8 +70,8 @@ class ProfileActivityTest { } every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} - every { mockUsersRepo.getUserData(any())} answers {} - every { mockUsersRepo.updateFieldString(any(), any(), any()) } answers {} + every { mockUsersRepo.getUserData(any(),any())} answers {} + every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} } @After From e0ceca2a5e69adf36541c7aae92185e4626b8bcd Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Mon, 2 May 2022 20:59:51 +0200 Subject: [PATCH 21/22] fix test partly --- .../java/ch/sdp/vibester/activity/ProfileActivityTest.kt | 1 - .../java/ch/sdp/vibester/activity/SearchUserActivityTest.kt | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt index e9a592f9b..693888ef0 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt @@ -70,7 +70,6 @@ class ProfileActivityTest { } every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} - every { mockUsersRepo.getUserData(any(),any())} answers {} every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {} } diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt index c5ab03440..607319414 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/SearchUserActivityTest.kt @@ -63,6 +63,8 @@ class SearchUserActivityTest { } every {mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(),any())} answers {} + every {mockUsersRepo.setSubFieldValue(any(), any(), any(), any())} answers {} + } @BindValue @JvmField @@ -191,13 +193,13 @@ class SearchUserActivityTest { /** * Custom functions to match the item views inside Recycle View */ - fun checkRecyclerSubViews( recyclerViewId: Int, position: Int, itemMatcher: Matcher, subViewId: Int) { + private fun checkRecyclerSubViews( recyclerViewId: Int, position: Int, itemMatcher: Matcher, subViewId: Int) { onView(withId(recyclerViewId)).perform( RecyclerViewActions.scrollToPosition(position)) .check(matches(atPositionOnView(position, itemMatcher, subViewId))) } - fun atPositionOnView(position: Int, itemMatcher: Matcher, targetViewId: Int): Matcher { + private fun atPositionOnView(position: Int, itemMatcher: Matcher, targetViewId: Int): Matcher { return object : BoundedMatcher(RecyclerView::class.java) { override fun describeTo(description: Description) { description.appendText("has view id $itemMatcher at position $position") From 71b39aab9df31baaa8ce36cf469a0463b5408479 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Mon, 2 May 2022 21:03:59 +0200 Subject: [PATCH 22/22] UserProfileAdapter: fix the merge --- .../ch/sdp/vibester/user/UserProfileAdapter.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt b/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt index 2bccfbe17..3e6324411 100644 --- a/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt +++ b/app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt @@ -74,12 +74,15 @@ class UserProfileAdapter constructor(val users: MutableList, val authentic itemView.findViewById(R.id.profile_image).loadImg(user.image) val addFriendBtn = itemView.findViewById