Skip to content

Commit bdc0b73

Browse files
added test cases
1 parent eb67637 commit bdc0b73

23 files changed

Lines changed: 369 additions & 36 deletions

File tree

HiltAndroid/.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HiltAndroid/.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HiltAndroid/.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HiltAndroid/.idea/misc.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HiltAndroid/app/build.gradle

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ android {
2626
}
2727
}
2828
compileOptions {
29-
sourceCompatibility JavaVersion.VERSION_17
30-
targetCompatibility JavaVersion.VERSION_17
29+
sourceCompatibility JavaVersion.VERSION_11
30+
targetCompatibility JavaVersion.VERSION_11
3131
}
3232
kotlinOptions {
33-
jvmTarget = '17'
33+
jvmTarget = '11'
3434
}
3535

3636
buildFeatures {
@@ -82,16 +82,16 @@ dependencies {
8282

8383
implementation "androidx.navigation:navigation-fragment-ktx:2.6.0"
8484
implementation "androidx.navigation:navigation-ui-ktx:2.6.0"
85-
85+
testImplementation 'org.robolectric:robolectric:4.4'
8686
// Unit Testing
8787
// For Robolectric tests.
88-
// debugImplementation 'com.google.dagger:hilt-android-testing:2.44'
88+
debugImplementation 'com.google.dagger:hilt-android-testing:2.44'
8989
// ...with Kotlin.
90-
// kaptDebug 'com.google.dagger:hilt-android-compiler:2.44'
90+
kaptDebug 'com.google.dagger:hilt-android-compiler:2.44'
9191

9292
// hilt android test
93-
androidTestImplementation("com.google.dagger:hilt-android-testing:2.44")
94-
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.44")
93+
testImplementation("com.google.dagger:hilt-android-testing:2.44")
94+
kaptTest("com.google.dagger:hilt-android-compiler:2.44")
9595

9696
// Testing Libraries
9797
testImplementation 'org.mockito:mockito-core:4.6.1'
@@ -101,6 +101,12 @@ dependencies {
101101
testImplementation 'androidx.test:runner:1.4.0'
102102
testImplementation "android.arch.core:core-testing:1.1.1"
103103
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
104+
105+
106+
testImplementation 'androidx.test.espresso:espresso-core:3.3.0'
107+
testImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
108+
testImplementation 'androidx.test.espresso:espresso-intents:3.3.0'
109+
testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0")
104110
}
105111

106112
kapt {

HiltAndroid/app/src/androidTest/java/com/velmurugan/hiltandroid/ui/HomeFragmentTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.velmurugan.hiltandroid.ui
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
4-
import androidx.test.filters.MediumTest
54
import com.velmurugan.hiltandroid.launchFragmentInHiltContainer
5+
import com.velmurugan.hiltandroid.ui.home.HomeFragment
66
import dagger.hilt.android.testing.HiltAndroidRule
77
import dagger.hilt.android.testing.HiltAndroidTest
8-
import kotlinx.coroutines.ExperimentalCoroutinesApi
9-
import org.junit.Assert
108
import org.junit.Before
119
import org.junit.Rule
1210
import org.junit.Test

HiltAndroid/app/src/main/java/com/velmurugan/hiltandroid/data/MainRepository.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ import com.velmurugan.hiltandroid.Movie
44
import retrofit2.Response
55

66
interface MainRepository {
7+
78
suspend fun getAllMovies() : Response<List<Movie>>
9+
10+
suspend fun getVersion() : Response<Int>
11+
12+
813
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.velmurugan.hiltandroid.data
22

33
import dagger.hilt.android.qualifiers.ActivityContext
4+
import retrofit2.Response
45
import javax.inject.Inject
56

67
class MainRepositoryImpl @Inject constructor(private val apiService: ApiService): MainRepository {
78
override suspend fun getAllMovies() = apiService.getAllMovies()
9+
override suspend fun getVersion(): Response<Int> {
10+
return Response.success(4)
11+
}
812
}

HiltAndroid/app/src/main/java/com/velmurugan/hiltandroid/ui/HomeFragment.kt renamed to HiltAndroid/app/src/main/java/com/velmurugan/hiltandroid/ui/home/HomeFragment.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
package com.velmurugan.hiltandroid.ui
1+
package com.velmurugan.hiltandroid.ui.home
22

33
import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
77
import androidx.fragment.app.Fragment
88
import androidx.fragment.app.viewModels
9-
import com.velmurugan.hiltandroid.MainViewModel
109
import com.velmurugan.hiltandroid.databinding.FragmentHomeBinding
1110
import dagger.hilt.android.AndroidEntryPoint
1211
import javax.inject.Inject
1312

1413
@AndroidEntryPoint
1514
class HomeFragment: Fragment() {
1615

17-
private val viewModel: MainViewModel by viewModels()
16+
private val viewModel: HomeViewModel by viewModels()
1817

1918
lateinit var binding: FragmentHomeBinding
2019
@Inject

HiltAndroid/app/src/main/java/com/velmurugan/hiltandroid/MainViewModel.kt renamed to HiltAndroid/app/src/main/java/com/velmurugan/hiltandroid/ui/home/HomeViewModel.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
package com.velmurugan.hiltandroid
1+
package com.velmurugan.hiltandroid.ui.home
22

3-
import android.content.Context
4-
import android.util.Log
53
import androidx.lifecycle.MutableLiveData
64
import androidx.lifecycle.ViewModel
75
import androidx.lifecycle.viewModelScope
6+
import com.velmurugan.hiltandroid.Movie
87
import com.velmurugan.hiltandroid.data.MainRepository
98
import dagger.hilt.android.lifecycle.HiltViewModel
10-
import dagger.hilt.android.qualifiers.ActivityContext
11-
import dagger.hilt.android.scopes.ActivityScoped
12-
import kotlinx.coroutines.CoroutineScope
13-
import kotlinx.coroutines.Dispatchers
149
import kotlinx.coroutines.launch
1510
import javax.inject.Inject
1611

1712
@HiltViewModel
18-
class MainViewModel @Inject constructor(private val mainRepository: MainRepository): ViewModel() {
13+
class HomeViewModel @Inject constructor(private val mainRepository: MainRepository): ViewModel() {
1914

2015
val movieList = MutableLiveData<List<Movie>>()
2116
val progressBarStatus = MutableLiveData<Boolean>()

0 commit comments

Comments
 (0)