From 4459d32c9f8faf5d350de8c9ea5d8305cfbffe6a Mon Sep 17 00:00:00 2001 From: MaximeZmt Date: Wed, 11 May 2022 22:00:07 +0200 Subject: [PATCH] fixed reviews --- .../sdp/vibester/helper/IntentSwitcherTest.kt | 56 +++++++++++++++++++ .../activity/AuthenticationActivity.kt | 2 +- .../vibester/activity/DeleteSongsActivity.kt | 2 +- .../sdp/vibester/activity/DownloadActivity.kt | 2 +- .../vibester/activity/GameSetupActivity.kt | 2 +- .../activity/IncorrectSongsActivity.kt | 2 +- .../activity/LyricsBelongGameActivity.kt | 4 -- .../sdp/vibester/activity/ProfileActivity.kt | 4 +- .../sdp/vibester/activity/WelcomeActivity.kt | 12 ++-- .../ch/sdp/vibester/helper/IntentSwitcher.kt | 4 +- 10 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt diff --git a/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt b/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt new file mode 100644 index 000000000..694507191 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt @@ -0,0 +1,56 @@ +package ch.sdp.vibester.helper + +import android.content.Intent +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.intent.Intents +import androidx.test.espresso.intent.matcher.IntentMatchers +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import ch.sdp.vibester.R +import ch.sdp.vibester.activity.GameSetupActivity +import ch.sdp.vibester.activity.WelcomeActivity +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.io.Serializable + + +@HiltAndroidTest +@RunWith(AndroidJUnit4::class) +class IntentSwitcherTest { + @get:Rule + var hiltRule = HiltAndroidRule(this) + + + @Before + fun setUp() { + hiltRule.inject() + Intents.init() + } + + @After + fun clean() { + Intents.release() + } + + @Test + fun checkIntentOnPlay() { + val intent = Intent(ApplicationProvider.getApplicationContext(), WelcomeActivity::class.java) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + val testMap: HashMap = HashMap() + testMap.put("test", true) + + IntentSwitcher.switch(ApplicationProvider.getApplicationContext(), GameSetupActivity::class.java, testMap) + Intents.intended(IntentMatchers.hasComponent(GameSetupActivity::class.java.name)) + Intents.intended(IntentMatchers.hasExtra("test", true)) + } + +} \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt index 3e9b9610e..f1990fc10 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt @@ -99,7 +99,7 @@ class AuthenticationActivity : AppCompatActivity() { * Listener bound to the red return button in the Authentication activity. */ fun returnToMainListener(view: View) { - IntentSwitcher.switch(this, WelcomeActivity::class.java, null) + IntentSwitcher.switch(this, WelcomeActivity::class.java) finish() } diff --git a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt index b39934597..f76049ba0 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt @@ -34,7 +34,7 @@ class DeleteSongsActivity : AppCompatActivity() { setContentView(R.layout.activity_delete_songs) findViewById(R.id.delete_returnToMain).setOnClickListener { - IntentSwitcher.switch(this, WelcomeActivity::class.java, null) + IntentSwitcher.switch(this, WelcomeActivity::class.java) } val layout: LinearLayout = findViewById(R.id.delete_songs_linear) diff --git a/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt index 5b82d01ab..dfa5981ad 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt @@ -57,7 +57,7 @@ class DownloadActivity : AppCompatActivity() { } findViewById(R.id.download_returnToMain).setOnClickListener { - IntentSwitcher.switch(this, WelcomeActivity::class.java, null) + IntentSwitcher.switch(this, WelcomeActivity::class.java) } var broadcast = object:BroadcastReceiver() { 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 5e816f5fe..7c15fddd3 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/GameSetupActivity.kt @@ -46,7 +46,7 @@ class GameSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListene private fun setReturnBtnListener() { findViewById(R.id.gameSetup_returnToMain).setOnClickListener { if (findViewById(R.id.chooseGame).visibility == VISIBLE) { - IntentSwitcher.switch(this, WelcomeActivity::class.java, null) + IntentSwitcher.switch(this, WelcomeActivity::class.java) finish() } else if (findViewById(R.id.chooseGenre).visibility == VISIBLE) { findViewById(R.id.chooseGame).visibility = VISIBLE diff --git a/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt index e79db9d75..9d95a182a 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt @@ -33,7 +33,7 @@ class IncorrectSongsActivity : AppCompatActivity() { findViewById