androidTest: Test exodus_trackers.json file

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-08-19 10:17:43 +05:30
parent 00713f961c
commit 1aa55b5578
5 changed files with 80 additions and 44 deletions

View File

@@ -1,41 +0,0 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Aurora Store is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.aurora.store
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.aurora.aurorastore", appContext.packageName)
}
}

View File

@@ -0,0 +1,17 @@
package com.aurora.store
import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltTestApplication
class HiltInstrumentationTestRunner: AndroidJUnitRunner() {
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}

View File

@@ -0,0 +1,50 @@
package com.aurora.store.data.providers
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.json.JSONObject
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class ExodusDataProviderTest {
@get:Rule
var hiltAndroidRule = HiltAndroidRule(this)
@Inject
lateinit var exodusTrackers: JSONObject
@Before
fun setup() {
hiltAndroidRule.inject()
}
@Test
fun testTrackersJsonIsNotEmpty() {
assertThat(exodusTrackers.toString()).isNotEmpty()
}
@Test
fun testTrackersJsonContainsTrackers() {
val trackers = mapOf(
"com.facebook.flipper" to 392,
"com.google.analytics." to 48,
"com.google.firebase.firebase_analytics" to 49,
"com.google.ads." to 312
)
trackers.forEach { (codeSignature, id) ->
assertThat(
exodusTrackers.getJSONObject(id.toString())
.getString("code_signature")
.contains(codeSignature)
).isTrue()
}
}
}