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

Commit

Permalink
merged with main
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeZmt committed May 11, 2022
2 parents 4459d32 + 0ca560e commit ccc44b5
Show file tree
Hide file tree
Showing 49 changed files with 713 additions and 545 deletions.
16 changes: 12 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ android {
versionCode 1
versionName "1.0"

// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "ch.sdp.vibester.CustomTestRunner"
}

Expand Down Expand Up @@ -71,24 +70,28 @@ apply plugin: 'com.google.gms.google-services'
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.0.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0'
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'junit:junit:4.13.2'
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.1'
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.2'
implementation "androidx.cardview:cardview:1.0.0"
implementation("androidx.fragment:fragment:1.4.1")
implementation("androidx.fragment:fragment-ktx:1.4.1")

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20180813'
testImplementation 'org.robolectric:robolectric:4.6'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0'
testImplementation 'org.mockito:mockito-inline:2.13.0'
debugImplementation "androidx.fragment:fragment-testing:1.5.0-beta01"
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand All @@ -101,6 +104,10 @@ dependencies {
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
implementation 'android.arch.navigation:navigation-ui:1.0.0'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation ('com.github.bumptech.glide:glide:4.13.0', {
exclude group: 'com.android.support'
Expand All @@ -119,6 +126,7 @@ dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
implementation 'com.google.zxing:core:3.4.1'
implementation 'com.github.kenglxn.QRGen:android:2.6.0'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
}

tasks.withType(Test) {
Expand Down
65 changes: 65 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/HiltExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ch.sdp.vibester

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import androidx.annotation.StyleRes
import androidx.core.util.Preconditions
import androidx.fragment.app.Fragment
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider

/**
* launchFragmentInContainer from the androidx.fragment:fragment-testing library
* is NOT possible to use right now as it uses a hardcoded Activity under the hood
* (i.e. [EmptyFragmentActivity]) which is not annotated with @AndroidEntryPoint.
*
* As a workaround, use this function that is equivalent. It requires you to add
* [HiltTestActivity] in the debug folder and include it in the debug AndroidManifest.xml file
* as can be found in this project.
*/
inline fun <reified T : Fragment> launchFragmentInHiltContainer(
fragmentArgs: Bundle? = null,
@StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
crossinline action: Fragment.() -> Unit = {}
) {
val startActivityIntent = Intent.makeMainActivity(
ComponentName(
ApplicationProvider.getApplicationContext(),
HiltTestActivity::class.java
)
).putExtra(
"androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity.THEME_EXTRAS_BUNDLE_KEY",
themeResId
)

ActivityScenario.launch<HiltTestActivity>(startActivityIntent).onActivity { activity ->
val fragment: Fragment = activity.supportFragmentManager.fragmentFactory.instantiate(
Preconditions.checkNotNull(T::class.java.classLoader),
T::class.java.name
)
fragment.arguments = fragmentArgs
activity.supportFragmentManager
.beginTransaction()
.add(android.R.id.content, fragment, "")
.commitNow()

fragment.action()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class AuthenticationActivityTest {
fun returnToMain() {
every { mockAuthenticator.isLoggedIn() } returns false
onView(withId(R.id.authentication_returnToMain)).perform(click())
Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name))
Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ class DeleteSongsActivityTest {
Intents.release()
}


@Test
fun checkIntentOnGoBack() {
onView(withId(R.id.delete_returnToMain)).perform(click())
intended(hasComponent(WelcomeActivity::class.java.name))
intended(hasComponent(MainActivity::class.java.name))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class DownloadActivityTest {
@Test
fun checkIntentOnGoBack() {
onView(withId(R.id.download_returnToMain)).perform(click())
Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name))
Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ class IncorrectSongsActivityTest {
@Test
fun checkIntentOnGoBack() {
onView(withId(R.id.incorrect_songs_back_to_welcome)).perform(click())
intended(hasComponent(WelcomeActivity::class.java.name))
intended(hasComponent(MainActivity::class.java.name))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class LyricsBelongGameActivityTest {
onView(withId(R.id.lyricMatchButton)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}*/


@Test
fun getAndCheckLyricsGivesCorrectAnswerWhenMatch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class ProfileActivityTest {

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.profile_returnToMain)).perform(click())

Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name))
Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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 dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.not
import org.junit.After
import org.junit.Before
Expand All @@ -20,14 +22,18 @@ import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class ScoreBoardActivityTest {

@Rule
@JvmField
@get:Rule(order=0)
var hiltRule = HiltAndroidRule(this)

@get:Rule(order=1)
val activityRule = ActivityScenarioRule(ScoreBoardActivity::class.java)

@Before
fun setUp() {
hiltRule.inject()
Intents.init()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class TypingGameActivityTest {
assertEquals(expectedSize, myTest.minimumWidth)
}

/*
@Test
fun guessLayoutTest() {
createMockDataGetter()
Expand Down Expand Up @@ -187,6 +188,7 @@ class TypingGameActivityTest {
assertEquals(songTest.getTrackName(), gameManager.getCurrentSong().getTrackName())
assertEquals(gameManager.getScore(), 1)
}
*/

@Test
fun checkAnswerCorrectTest() {
Expand Down
Loading

0 comments on commit ccc44b5

Please sign in to comment.