Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Refactor #100

Merged
merged 15 commits into from
Mar 21, 2022
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ android {
includeAndroidResources = true
}
}
buildFeatures {
viewBinding true
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
Expand Down
49 changes: 0 additions & 49 deletions app/src/androidTest/java/ch/sdp/vibester/EndToEndTest.kt

This file was deleted.

29 changes: 0 additions & 29 deletions app/src/androidTest/java/ch/sdp/vibester/GreetingActivityTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class LyricTemporaryTest {
fun canGetLyricsFromAPI() {
val service = LyricsOVHApiInterface.create("https://api.lyrics.ovh/")
val lyric = service.getLyrics("Imagine Dragons", "Believer").execute()
assertThat(lyric.body().lyrics, equalTo("First things first\r\n" +
//Adding a replace because sometimes the api put some additional text
assertThat(
lyric.body().lyrics?.replace("\n", "")?.replace("\r","")
?.replace("Paroles de la chanson Believer par Imagine Dragons",""), equalTo(("First things first\r\n" +
"I'm say all the words inside my head\r\n" +
"I'm fired up and tired of the way that things have been, oh-ooh\r\n" +
"The way that things have been, oh-ooh\r\nSecond thing second\r\n" +
Expand Down Expand Up @@ -50,7 +53,7 @@ class LyricTemporaryTest {
"\n\nYou made me a, you made me a believer, believer\n\nPain!\n\n" +
"You break me down, you build me up, believer, believer\n\nPain!\n\n" +
"I let the bullets fly, oh let them rain\n\nMy life, my love, my drive, they came from...\n\n" +
"Pain!\n\nYou made me a, you made me a believer, believer"))
"Pain!\n\nYou made me a, you made me a believer, believer").replace("\r", "").replace("\n","")))
}

@Test
Expand All @@ -60,7 +63,7 @@ class LyricTemporaryTest {
val intent = Intent(
ApplicationProvider.getApplicationContext(), LyricTemporary::class.java
)
val scn: ActivityScenario<GreetingActivity> = ActivityScenario.launch(intent)
val scn: ActivityScenario<LyricTemporary> = ActivityScenario.launch(intent)
onView(withId(R.id.artistForLyric)).perform(typeText(inputArtistName), closeSoftKeyboard())
onView(withId(R.id.trackForLyric)).perform(typeText(inputTrackName), closeSoftKeyboard())
onView(withId(R.id.validateForLyric)).perform(click())
Expand Down
33 changes: 0 additions & 33 deletions app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.sdp.vibester
package ch.sdp.vibester.activity

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
Expand All @@ -10,6 +10,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import ch.sdp.vibester.R
import ch.sdp.vibester.auth.FireBaseAuthenticator
import org.junit.Assert.assertEquals
import org.junit.Rule
Expand All @@ -24,7 +25,7 @@ import kotlin.random.Random
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class SignInActivityTest {
class AuthenticationActivityTest {

@Test
fun useAppContext() {
Expand All @@ -35,7 +36,7 @@ class SignInActivityTest {

@get:Rule
val testRule = ActivityScenarioRule(
Register::class.java
AuthenticationActivity::class.java
)

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.sdp.vibester
package ch.sdp.vibester.activity

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
Expand All @@ -14,19 +15,19 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.scoreboard.ScoreBoardActivity
import ch.sdp.vibester.R
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class GameEndingScreenTest {
class GameEndingActivityTest {

@Rule
@JvmField
val activityRule = ActivityScenarioRule(GameEndingScreen::class.java)
val activityRule = ActivityScenarioRule(GameEndingActivity::class.java)

@Before
fun setUp() {
Expand Down Expand Up @@ -55,7 +56,11 @@ class GameEndingScreenTest {

@Test
fun checkIntentOnCalled() {
val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingScreen::class.java)
val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)

//Start an activity from outside an activity
intent.setFlags(FLAG_ACTIVITY_NEW_TASK)

intent.putExtra("playerName", name)
intent.putExtra("nbIncorrectSong", nbInc)
//intent.putExtra("incorrect_songs", inc)
Expand All @@ -67,7 +72,9 @@ class GameEndingScreenTest {

intent.putExtra("stat_1", "Hello there")
intent.putExtra("stat_res_1", "General Kenobi")
val scn: ActivityScenario<GreetingActivity> = ActivityScenario.launch(intent)

//keep this val to help kotlin inferring value type
val uselessVal: ActivityScenario<GameEndingActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.end_stat1)).check(matches(withText(stats[0])))
onView(withId(R.id.end_stat1_res)).check(matches(withText(statsRes[0])))
Expand All @@ -76,26 +83,26 @@ class GameEndingScreenTest {

@Test
fun checkIntentOnIncorrectSongs() {
val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingScreen::class.java)
val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)

intent.putExtra("playerName", name)
intent.putExtra("nbIncorrectSong", nbInc)
//intent.putExtra("incorrect_songs", inc)
//intent.putExtra("Stat_names", stats)
//intent.putExtra("Stat_values", statsRes)
intent.putExtra("incorrect_song_1", "One")
intent.putExtra("incorrect_song_2", "Two")
intent.putExtra("incorrect_song_3", "Three")

intent.putExtra("stat_1", "Hello There")
intent.putExtra("stat_res_1", "General Kenobi")
val scn: ActivityScenario<GreetingActivity> = ActivityScenario.launch(intent)

//keep this val to help kotlin inferring value type
val uselessVal: ActivityScenario<GameEndingActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.end_go_to_inc)).perform(click())

intended(hasComponent(IncorrectSongsActivity::class.java.name))
intended(hasExtra("nb_false", nbInc))
//intended(hasExtra("incorrect_songs", inc))
intended(hasExtra("incorrect_song_1", inc[0]))
intended(hasExtra("incorrect_song_2", inc[1]))
intended(hasExtra("incorrect_song_3", inc[2]))
intended(hasComponent(IncorrectSongsScreen::class.java.name))
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package ch.sdp.vibester
package ch.sdp.vibester.activity

import android.widget.AdapterView
import androidx.test.espresso.Espresso
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onData
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.rules.ActivityScenarioRule
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.intent.matcher.IntentMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.withSpinnerText
import ch.sdp.vibester.R
import org.hamcrest.Matchers
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class GameSetupScreenTest {

class GameSetupActivityTest {

@get: Rule
val activityRule = ActivityScenarioRule(GameSetupScreen::class.java)
val activityRule = ActivityScenarioRule(GameSetupActivity::class.java)

@Before
fun setUp() {
Expand All @@ -42,6 +40,11 @@ class GameSetupScreenTest {
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One")))
}

@Test
fun checkNothingSelect() {
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One")))
}

@Test
fun checkCustomSelectOne() {
onView(withId(R.id.nb_player_spinner)).perform(click())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package ch.sdp.vibester
package ch.sdp.vibester.activity

import android.app.AlertDialog
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.CoreMatchers.allOf
import ch.sdp.vibester.R
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -84,7 +82,7 @@ class GamescreenActivityTest {
@Test
fun checkIntentOnEnding() {
onView(withId(R.id.go_to_end)).perform(click())
intended(hasComponent(GameEndingScreen::class.java.name))
intended(hasComponent(GameEndingActivity::class.java.name))
intended(hasExtra("playerName", "Arda"))
intended(hasExtra("nbIncorrectSong", 3))
/*intended(hasExtra("incorrect_songs", arrayOf("One", "Two", "Three")))
Expand Down
Loading