mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2025-12-10 02:05:20 +00:00
Merge branch 'refs/heads/master' into instrumtation_test_fix
# Conflicts: # app/src/androidTestAtlasWeather/java/com/appttude/h_mal/atlas_weather/application/TestAppClass.kt
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.appttude.h_mal.atlas_weather.application
|
||||
|
||||
import androidx.room.Room
|
||||
import androidx.test.espresso.IdlingRegistry
|
||||
import androidx.test.espresso.idling.CountingIdlingResource
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.appttude.h_mal.atlas_weather.data.location.LocationProvider
|
||||
import com.appttude.h_mal.atlas_weather.data.location.MockLocationProvider
|
||||
import com.appttude.h_mal.atlas_weather.data.network.NetworkModule
|
||||
import com.appttude.h_mal.atlas_weather.data.network.WeatherApi
|
||||
import com.appttude.h_mal.atlas_weather.data.network.interceptors.MockingNetworkInterceptor
|
||||
import com.appttude.h_mal.atlas_weather.data.network.interceptors.NetworkConnectionInterceptor
|
||||
import com.appttude.h_mal.atlas_weather.data.network.interceptors.QueryParamsInterceptor
|
||||
import com.appttude.h_mal.atlas_weather.data.network.networkUtils.loggingInterceptor
|
||||
import com.appttude.h_mal.atlas_weather.data.room.AppDatabase
|
||||
import com.appttude.h_mal.atlas_weather.data.room.Converter
|
||||
import java.io.BufferedReader
|
||||
|
||||
class TestAppClass : AppClass() {
|
||||
private val idlingResources = CountingIdlingResource("Data_loader")
|
||||
private val mockingNetworkInterceptor = MockingNetworkInterceptor(idlingResources)
|
||||
|
||||
lateinit var database: AppDatabase
|
||||
private val locationProvider: MockLocationProvider = MockLocationProvider()
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
IdlingRegistry.getInstance().register(idlingResources)
|
||||
}
|
||||
|
||||
override fun createNetworkModule(): WeatherApi {
|
||||
return NetworkModule().invoke<WeatherApi>(
|
||||
mockingNetworkInterceptor,
|
||||
NetworkConnectionInterceptor(this),
|
||||
QueryParamsInterceptor(),
|
||||
loggingInterceptor
|
||||
) as WeatherApi
|
||||
}
|
||||
|
||||
override fun createLocationModule(): LocationProvider {
|
||||
return locationProvider
|
||||
}
|
||||
|
||||
override fun createRoomDatabase(): AppDatabase {
|
||||
database = Room.inMemoryDatabaseBuilder(applicationContext, AppDatabase::class.java)
|
||||
.allowMainThreadQueries()
|
||||
.addTypeConverter(Converter(this))
|
||||
.build()
|
||||
return database
|
||||
}
|
||||
|
||||
fun stubUrl(url: String, rawPath: String, code: Int = 200) {
|
||||
val iStream =
|
||||
InstrumentationRegistry.getInstrumentation().context.assets.open("$rawPath.json")
|
||||
val data = iStream.bufferedReader().use(BufferedReader::readText)
|
||||
mockingNetworkInterceptor.addUrlStub(url = url, data = data, code = code)
|
||||
}
|
||||
|
||||
fun removeUrlStub(url: String) {
|
||||
mockingNetworkInterceptor.removeUrlStub(url = url)
|
||||
}
|
||||
|
||||
fun stubLocation(location: String, lat: Double = 0.00, long: Double = 0.00) {
|
||||
locationProvider.addLocationToList(location, lat, long)
|
||||
}
|
||||
|
||||
fun removeLocation(location: String) {
|
||||
locationProvider.removeLocationFromList(location)
|
||||
}
|
||||
|
||||
fun removeLocation(lat: Double, long: Double) {
|
||||
locationProvider.removeLocationFromList(lat, long)
|
||||
}
|
||||
|
||||
fun clearDatabase() {
|
||||
database.getWeatherDao().deleteAll()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<application
|
||||
android:name="com.appttude.h_mal.atlas_weather.application.AppClass"
|
||||
android:name="com.appttude.h_mal.atlas_weather.application.AtlasApp"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.appttude.h_mal.atlas_weather.application
|
||||
|
||||
import com.appttude.h_mal.atlas_weather.service.notification.NotificationHelper
|
||||
import com.appttude.h_mal.atlas_weather.service.notification.NotificationService
|
||||
import org.kodein.di.generic.bind
|
||||
import org.kodein.di.generic.instance
|
||||
import org.kodein.di.generic.provider
|
||||
import org.kodein.di.generic.singleton
|
||||
|
||||
|
||||
open class AtlasApp : AppClass() {
|
||||
|
||||
private lateinit var notificationService: NotificationService
|
||||
|
||||
override val flavourModule = super.flavourModule.copy {
|
||||
bind() from singleton {
|
||||
NotificationHelper(
|
||||
instance(),
|
||||
instance(),
|
||||
)
|
||||
}
|
||||
|
||||
bind() from singleton {
|
||||
NotificationService(this@AtlasApp).apply { notificationService = this }
|
||||
}
|
||||
|
||||
bind() from provider {
|
||||
ApplicationViewModelFactory(
|
||||
this@AtlasApp,
|
||||
instance(),
|
||||
instance(),
|
||||
instance(),
|
||||
instance()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// override fun onCreate() {
|
||||
// super.onCreate()
|
||||
// notificationService.schedulePushNotifications()
|
||||
// }
|
||||
|
||||
fun scheduleNotifications() = notificationService.schedulePushNotifications()
|
||||
|
||||
fun unscheduleNotifications() = notificationService.unschedulePushNotifications()
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:name="com.appttude.h_mal.atlas_weather.application.AppClass"
|
||||
android:name="com.appttude.h_mal.atlas_weather.application.MonoApp"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.appttude.h_mal.atlas_weather.application
|
||||
|
||||
import org.kodein.di.generic.bind
|
||||
import org.kodein.di.generic.instance
|
||||
import org.kodein.di.generic.provider
|
||||
|
||||
open class MonoApp : AppClass() {
|
||||
|
||||
override val flavourModule = super.flavourModule.copy {
|
||||
bind() from provider {
|
||||
ApplicationViewModelFactory(
|
||||
this@MonoApp,
|
||||
instance(),
|
||||
instance(),
|
||||
instance(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user