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

refactor createAPIService #126

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package ch.sdp.vibester

import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test

public class BuzzerScoreUpdaterTest {

// FIXME: Uncomment this when the infinite loop issue in the class is fixed
Expand Down
37 changes: 19 additions & 18 deletions app/src/androidTest/java/ch/sdp/vibester/GenreTemporaryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ package ch.sdp.vibester

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.*
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.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
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.activity.TypingGameActivity
import org.hamcrest.Matchers.*
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class GenreTemporaryTest {
private val SLEEP_TIME:Long = 2500
private val sleepTime: Long = 2500

@get:Rule
val testRule = ActivityScenarioRule(
Expand All @@ -46,45 +45,47 @@ class GenreTemporaryTest {
onView(withId(R.id.imagDragonsButton)).check(matches(isDisplayed()))
onView(withId(R.id.billieEilishButton)).check(matches(isDisplayed()))
}

@Test
fun rockButtonClick() {
onView(withId(R.id.rockButton)).perform(click())
Thread.sleep(SLEEP_TIME)
intended(hasComponent(TypingGameActivity::class.java.getName()))
Thread.sleep(sleepTime)
intended(hasComponent(TypingGameActivity::class.java.name))
}

@Test
fun topButtonClick() {
onView(withId(R.id.topTracksButton)).perform(click())
Thread.sleep(SLEEP_TIME)
Thread.sleep(sleepTime)

intended(hasComponent(TypingGameActivity::class.java.getName()))
intended(hasComponent(TypingGameActivity::class.java.name))
}

@Test
fun kpopButtonClick() {
onView(withId(R.id.kpopButton)).perform(click())
Thread.sleep(SLEEP_TIME)
intended(hasComponent(TypingGameActivity::class.java.getName()))
Thread.sleep(sleepTime)
intended(hasComponent(TypingGameActivity::class.java.name))
}

@Test
fun billieEilishButtonClick() {
onView(withId(R.id.billieEilishButton)).perform(click())
Thread.sleep(SLEEP_TIME)
intended(hasComponent(TypingGameActivity::class.java.getName()))
Thread.sleep(sleepTime)
intended(hasComponent(TypingGameActivity::class.java.name))
}

@Test
fun imagineDragonsButtonClick() {
onView(withId(R.id.imagDragonsButton)).perform(click())
Thread.sleep(SLEEP_TIME)
intended(hasComponent(TypingGameActivity::class.java.getName()))
Thread.sleep(sleepTime)
intended(hasComponent(TypingGameActivity::class.java.name))
}

@Test
fun btsButtonClick() {
onView(withId(R.id.btsButton)).perform(click())
Thread.sleep(SLEEP_TIME)
intended(hasComponent(TypingGameActivity::class.java.getName()))
Thread.sleep(sleepTime)
intended(hasComponent(TypingGameActivity::class.java.name))
}
}
75 changes: 40 additions & 35 deletions app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import ch.sdp.vibester.api.LyricsOVHApiInterface
import ch.sdp.vibester.api.ServiceBuilder
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -18,43 +17,49 @@ import org.junit.Test
class LyricTemporaryTest {
@Test
fun canGetLyricsFromAPI() {
val service = ServiceBuilder.buildService("https://api.lyrics.ovh/", LyricsOVHApiInterface::class.java)
val service = LyricsOVHApiInterface.createLyricService()
val lyric = service.getLyrics("Imagine Dragons", "Believer").execute()
//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" +
"Don't you tell me what you think that I can be\n\n" +
"I'm the one at the sail, I'm the master of my sea, oh-ooh\n\n" +
"The master of my sea, oh-ooh\n\n\n\nI was broken from a young age\n\n" +
"Taking my sulkin to the masses\n\nWrite down my poems for the few\n\n" +
"That looked at me took to me, shook to me, feeling me\n\n" +
"Singing from heart ache from the pain\n\nTake up my message from the veins\n\n" +
"Speaking my lesson from the brain\n\nSeeing the beauty through the...\n\n\n\n" +
"Pain!\n\nYou made me a, you made me a believer, believer\n\nPain!" +
"\n\nYou 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, it came from...\n\n" +
"Pain!\n\nYou made me a, you made me a believer, believer\n\n\n\n" +
"Third things third\n\nSend a prayer to the ones up above\n\n" +
"All the hate that you've heard has turned your spirit to a dove, oh-ooh\n\n" +
"Your spirit up above, oh-ooh\n\n\n\nI was choking in the crowd\n\nLiving my brain up in the cloud\n\n" +
"Falling like ashes to the ground\n\nHoping my feelings, they would drown\n\n" +
"But they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" +
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!\n\n" +
"You 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\n\n\n\nLast things last\n\n" +
"By the grace of the fire and the flames\n\nYou're the face of the future, you're the blood in my veins, oh-ooh\n\n" +
"The blood in my veins, oh-ooh\n\nBut they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" +
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!" +
"\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").replace("\r", "").replace("\n","")))
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" +
"Don't you tell me what you think that I can be\n\n" +
"I'm the one at the sail, I'm the master of my sea, oh-ooh\n\n" +
"The master of my sea, oh-ooh\n\n\n\nI was broken from a young age\n\n" +
"Taking my sulkin to the masses\n\nWrite down my poems for the few\n\n" +
"That looked at me took to me, shook to me, feeling me\n\n" +
"Singing from heart ache from the pain\n\nTake up my message from the veins\n\n" +
"Speaking my lesson from the brain\n\nSeeing the beauty through the...\n\n\n\n" +
"Pain!\n\nYou made me a, you made me a believer, believer\n\nPain!" +
"\n\nYou 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, it came from...\n\n" +
"Pain!\n\nYou made me a, you made me a believer, believer\n\n\n\n" +
"Third things third\n\nSend a prayer to the ones up above\n\n" +
"All the hate that you've heard has turned your spirit to a dove, oh-ooh\n\n" +
"Your spirit up above, oh-ooh\n\n\n\nI was choking in the crowd\n\nLiving my brain up in the cloud\n\n" +
"Falling like ashes to the ground\n\nHoping my feelings, they would drown\n\n" +
"But they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" +
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!\n\n" +
"You 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\n\n\n\nLast things last\n\n" +
"By the grace of the fire and the flames\n\nYou're the face of the future, you're the blood in my veins, oh-ooh\n\n" +
"The blood in my veins, oh-ooh\n\nBut they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" +
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!" +
"\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").replace(
"\r",
""
).replace("\n", "")
)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.random.Random
*/
@RunWith(AndroidJUnit4::class)
class AuthenticationActivityTest {
private val SLEEP_TIME: Long = 5000
private val sleepTime: Long = 5000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use camel case for all the constants from now on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will say yes but only when they are inside a class


@Test
fun useAppContext() {
Expand All @@ -47,7 +47,7 @@ class AuthenticationActivityTest {
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
onView(withId(R.id.logIn)).perform(click())
Thread.sleep(SLEEP_TIME)
Thread.sleep(sleepTime)
onView(withId(R.id.email)).check(matches(withText("Authentication error")))
}

Expand All @@ -58,7 +58,7 @@ class AuthenticationActivityTest {
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
onView(withId(R.id.createAcc)).perform(click())
Thread.sleep(SLEEP_TIME)
Thread.sleep(sleepTime)
onView(withId(R.id.email)).check(matches(withText("Authentication error")))
}

Expand Down Expand Up @@ -97,14 +97,14 @@ class AuthenticationActivityTest {
@Test
fun derinTest() {
val a = FireBaseAuthenticator()
a.googleActivityResult(-1,-1,null)
a.googleActivityResult(-1, -1, null)
onView(withId(R.id.email)).check(matches(withText("TextView")))
}

@Test
fun ardaTest() {
val a = FireBaseAuthenticator()
a.googleActivityResult(1000,-1,null)
a.googleActivityResult(1000, -1, null)
onView(withId(R.id.email)).check(matches(withText("TextView")))
}

Expand All @@ -115,7 +115,7 @@ class AuthenticationActivityTest {
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
onView(withId(R.id.logIn)).perform(click())
Thread.sleep(SLEEP_TIME)
Thread.sleep(sleepTime)
onView(withId(R.id.email)).check(matches(withText("[email protected]")))
}

Expand All @@ -127,7 +127,7 @@ class AuthenticationActivityTest {
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
onView(withId(R.id.createAcc)).perform(click())
Thread.sleep(SLEEP_TIME)
Thread.sleep(sleepTime)
onView(withId(R.id.email)).check(matches(withText(randomInt.toString().plus("@gg.com"))))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,27 @@ class GameEndingActivityTest {
@Test
fun checkIntentOnCalled() {
incArray.addAll(arrayOf("One", "Two", "Three"))
statNames.addAll(arrayOf("Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"))
statRes.addAll(arrayOf("General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"))

val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)
statNames.addAll(
arrayOf(
"Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"
)
)
statRes.addAll(
arrayOf(
"General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"
)
)

val intent =
Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)
intent.putExtra("playerName", name)
intent.putExtra("nbIncorrectSong", nbInc)

Expand All @@ -85,18 +94,27 @@ class GameEndingActivityTest {
@Test
fun checkIntentOnIncorrectSongs() {
incArray.addAll(arrayOf("One", "Two", "Three"))
statNames.addAll(arrayOf("Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"))
statRes.addAll(arrayOf("General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"))

val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)
statNames.addAll(
arrayOf(
"Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"
)
)
statRes.addAll(
arrayOf(
"General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"
)
)

val intent =
Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java)
intent.putExtra("playerName", name)
intent.putExtra("nbIncorrectSong", nbInc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package ch.sdp.vibester.activity


import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.intent.Intents
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
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.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.intent.matcher.IntentMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.withSpinnerText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import ch.sdp.vibester.R
import org.hamcrest.Matchers
import org.junit.After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,26 @@ class GamescreenActivityTest {
incArray.addAll(arrayOf("One", "Two", "Three"))

val statNames: ArrayList<String> = arrayListOf()
statNames.addAll(arrayOf("Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"))
statNames.addAll(
arrayOf(
"Hello there",
"Second Stat",
"Third Stat",
"Fourth Stat",
"Fifth Stat"
)
)

val statVal: ArrayList<String> = arrayListOf()
statVal.addAll(arrayOf("General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"))
statVal.addAll(
arrayOf(
"General Kenobi",
"----- *2 -----",
"----- *3 -----",
"----- *4 -----",
"----- *5 -----"
)
)

onView(withId(R.id.go_to_end)).perform(click())
intended(hasComponent(GameEndingActivity::class.java.name))
Expand Down
Loading