Skip to content

Commit

Permalink
Clean greadle file & update decencies, update UI test by Hilt annotat…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
ahmedeltaher committed Jan 31, 2021
1 parent 5345513 commit 3c0711a
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 179 deletions.
104 changes: 31 additions & 73 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-platform-android'
apply plugin: 'dagger.hilt.android.plugin'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'kotlin-platform-android'
id 'dagger.hilt.android.plugin'
}


android {
compileSdkVersion 30
buildToolsVersion '30.0.2'
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId 'com.eltaher.task'
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "com.task.CustomTestRunner"
}
buildFeatures{
buildFeatures {
viewBinding = true
}
buildTypes {
Expand All @@ -32,7 +33,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

flavorDimensions "default"
productFlavors {
dev {
Expand All @@ -47,32 +47,21 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
defaultConfig {
testInstrumentationRunnerArguments clearPackageData: 'true'
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst 'META-INF/kotlinx-io.kotlin_module'
pickFirst 'META-INF/atomicfu.kotlin_module'
pickFirst 'META-INF/kotlinx-coroutines-core.kotlin_module'
pickFirst 'META-INF/kotlinx-coroutines-io.kotlin_module'
}

configurations.all {
resolutionStrategy {
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"

}
}

defaultConfig {
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
unitTests.returnDefaultValues = true
}

android {
sourceSets {
String sharedTestDir = 'src/sharedTest/resources'
Expand All @@ -90,71 +79,40 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.annotation:annotation:$annotationVersion"

implementation "com.squareup.picasso:picasso:$picassoVersion"
androidTestImplementation "androidx.test.ext:junit-ktx:$androidXJunitVersion"
/**-------------------testing libs------------------------------------------**/
//UI Testing , AndroidJUnitRunner and JUnit Rules &Espresso dependencies
//junit 5
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.platform:junit-platform-runner:$junitRunnerVersion"
androidTestImplementation "androidx.test.ext:junit:$androidXJunitVersion"
testImplementation "io.mockk:mockk:$mockVersion"
androidTestImplementation "org.assertj:assertj-core:$assertjVersion"
androidTestImplementation "androidx.arch.core:core-testing:$coreTestingVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoIntentsVersion"
androidTestImplementation ("androidx.test.espresso:espresso-core:$espressoCoreVersion",{
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation "androidx.test:runner:$runnerVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTestVersion"
implementation "androidx.arch.core:core-testing:$coreTestingVersion"
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
implementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
implementation "androidx.arch.core:core-testing:$coreTestingVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTestVersion"

/**-------------------------------------------------------------**/

//android support & recyclerview
implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
//android support
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "com.google.android.material:material:$materialVersion"

implementation "androidx.coordinatorlayout:coordinatorlayout:$coordinatorLayoutVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation "androidx.cardview:cardview:$cardViewVersion"



//Logging
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpInterceptorVersion"

// retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"
implementation "com.squareup.moshi:moshi:$moshiVersion"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"

//picasso
implementation "com.squareup.picasso:picasso:$picassoVersion"

//MultiDex
implementation "androidx.multidex:multidex:$multiDexVersion"

testImplementation "io.mockk:mockk:$mockVersion"

//coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesCoreVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutinesCommonVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleExtensionsVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleKTXVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleKTXVersion"
implementation "androidx.core:core-ktx:$coreKtxVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpInterceptorVersion"
implementation("com.github.bumptech.glide:glide:$glid") {
exclude group: "com.android.support"
}
implementation "androidx.activity:activity-ktx:$activityKtxVersion"

implementation 'com.google.dagger:hilt-android:2.31.2-alpha'
kapt 'com.google.dagger:hilt-android-compiler:2.31.2-alpha'
// Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_viewmodels"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version"
}
kapt {
correctErrorTypes true
Expand Down
4 changes: 0 additions & 4 deletions app/src/androidTest/java/com/task/AppTest.kt

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/androidTest/java/com/task/CustomTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.task
import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltTestApplication

/**
* A custom [AndroidJUnitRunner] used to replace the application used in tests with a
* [CustomTestRunner].
*/
class CustomTestRunner : AndroidJUnitRunner() {

override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, AppTest::class.java.name, context)
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}
6 changes: 5 additions & 1 deletion app/src/androidTest/java/com/task/di/TestDataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.hilt.testing.TestInstallIn
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [DataModule::class]
)
abstract class TestDataModule {
@Binds
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ import androidx.test.espresso.IdlingResource
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.task.R
import com.task.RECIPE_ITEM_KEY
import com.task.TestUtil.initData
import com.task.TestUtil.recipes
import com.task.RECIPE_ITEM_KEY
import com.task.utils.EspressoIdlingResource
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* Created by AhmedEltaher
*/

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

@get:Rule
var hiltRule = HiltAndroidRule(this)

@get:Rule
var mActivityTestRule = ActivityTestRule(DetailsActivity::class.java, true, false)
private var mIdlingResource: IdlingResource? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.RootMatchers.withDecorView
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.task.R
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.not
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Thread.sleep


/**
* Created by AhmedEltaher
*/
@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class LoginActivityTest {

@get:Rule
var hiltRule = HiltAndroidRule(this)

@get:Rule
var mActivityTestRule = IntentsTestRule(LoginActivity::class.java, true, false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.task.DataStatus
import com.task.R
import com.task.TestUtil.dataStatus
import com.task.TestUtil.recipes
import com.task.utils.EspressoIdlingResource
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers
import org.hamcrest.Matchers.not
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Thread.sleep

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

@get:Rule
var hiltRule = HiltAndroidRule(this)

@get:Rule
var mActivityTestRule = ActivityTestRule(RecipesListActivity::class.java, false, false)
private var mIdlingResource: IdlingResource? = null
Expand Down
12 changes: 1 addition & 11 deletions app/src/main/java/com/task/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,4 @@ import dagger.hilt.android.HiltAndroidApp
* Created by AhmedEltaher
*/
@HiltAndroidApp
open class App : Application() {

override fun onCreate() {
super.onCreate()
context = applicationContext
}

companion object {
lateinit var context: Context
}
}
open class App : Application()
19 changes: 10 additions & 9 deletions app/src/main/java/com/task/data/error/mapper/ErrorMapper.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.task.data.error.mapper

import com.task.App
import android.content.Context
import com.task.R
import com.task.data.error.*
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class ErrorMapper @Inject constructor() : ErrorMapperInterface {
class ErrorMapper @Inject constructor(@ApplicationContext val context: Context) : ErrorMapperSource {

override fun getErrorString(errorId: Int): String {
return App.context.getString(errorId)
return context.getString(errorId)
}

override val errorsMap: Map<Int, String>
get() = mapOf(
Pair(NO_INTERNET_CONNECTION, getErrorString(R.string.no_internet)),
Pair(NETWORK_ERROR, getErrorString(R.string.network_error)),
Pair(PASS_WORD_ERROR, getErrorString(R.string.invalid_password)),
Pair(USER_NAME_ERROR, getErrorString(R.string.invalid_username)),
Pair(CHECK_YOUR_FIELDS, getErrorString(R.string.invalid_username_and_password)),
Pair(SEARCH_ERROR, getErrorString(R.string.search_error))
Pair(NO_INTERNET_CONNECTION, getErrorString(R.string.no_internet)),
Pair(NETWORK_ERROR, getErrorString(R.string.network_error)),
Pair(PASS_WORD_ERROR, getErrorString(R.string.invalid_password)),
Pair(USER_NAME_ERROR, getErrorString(R.string.invalid_username)),
Pair(CHECK_YOUR_FIELDS, getErrorString(R.string.invalid_username_and_password)),
Pair(SEARCH_ERROR, getErrorString(R.string.search_error))
).withDefault { getErrorString(R.string.network_error) }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.task.data.error.mapper

interface ErrorMapperInterface {
interface ErrorMapperSource {
fun getErrorString(errorId: Int): String
val errorsMap: Map<Int, String>
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/task/data/local/LocalData.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.task.data.local

import android.content.Context
import android.content.SharedPreferences
import com.task.App.Companion.context
import com.task.FAVOURITES_KEY
import com.task.SHARED_PREFERENCES_FILE_NAME
import com.task.data.Resource
import com.task.data.dto.login.LoginRequest
import com.task.data.dto.login.LoginResponse
import com.task.FAVOURITES_KEY
import com.task.SHARED_PREFERENCES_FILE_NAME
import com.task.data.error.PASS_WORD_ERROR
import javax.inject.Inject

/**
* Created by AhmedEltaher
*/

class LocalData @Inject constructor() {
class LocalData @Inject constructor(val context: Context) {

fun doLogin(loginRequest: LoginRequest): Resource<LoginResponse> {
if (loginRequest == LoginRequest("[email protected]", "ahmed")) {
Expand Down
Loading

0 comments on commit 3c0711a

Please sign in to comment.