Skip to content

Commit 11962fa

Browse files
committed
[ADD]
- Add Coroutine Test Dependency on Dependencies.kt - Add MapperUnitTest.kt, - Add PlaceRepoUnitTest.kt [Commit] - NetworkUnitTest.kt
1 parent 7f085a1 commit 11962fa

File tree

9 files changed

+90
-23
lines changed

9 files changed

+90
-23
lines changed

.idea/deploymentTargetDropDown.xml

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/src/main/java/Dependencies.kt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ object Plugins {
5151
object Dependencies {
5252
const val androidx_core = "androidx.core:core:${Versions.core}"
5353
const val coroutine = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutine}"
54+
const val coroutine_test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutine}"
5455

5556
const val junit = "junit:junit:${Versions.junit}"
5657
const val androidx_junit = "androidx.test.ext:junit:${Versions.androidx_junit}"

core/data/src/test/java/com/example/data/ExampleUnitTest.kt core/data/src/test/java/com/example/data/DataBaseRepoUnitTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.junit.Assert.*
99
*
1010
* See [testing documentation](http://d.android.com/tools/testing).
1111
*/
12-
class ExampleUnitTest {
12+
class DataBaseRepoUnitTest {
1313
@Test
1414
fun addition_isCorrect() {
1515
assertEquals(4, 2 + 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.data
2+
3+
import org.junit.Before
4+
5+
/**
6+
* Mapper local unit test
7+
*/
8+
class MapperUnitTest {
9+
10+
@Before
11+
fun init() {
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.example.data
2+
3+
class PlaceRepoUnitTest {
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.example.network
1+
package com.example.database
22

33
/**
44
* Example local unit test, which will execute on the development machine (host).
55
*
66
* See [testing documentation](http://d.android.com/tools/testing).
77
*/
8-
class ExampleUnitTest {
8+
class DataBaseUnitTest {
99

1010
}

core/database/src/test/java/com/example/database/ExampleUnitTest.kt

-17
This file was deleted.

core/network/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dependencies {
3333
implementation(project(Module.model))
3434

3535
testImplementation(Dependencies.junit)
36+
testImplementation(Dependencies.coroutine_test)
3637
androidTestImplementation(Dependencies.androidx_junit)
3738

3839
implementation(Dependencies.retrofit2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.example.network
2+
3+
import com.example.network.api.RetrofitPlaceAPI
4+
import com.example.network.constant.Constants
5+
import junit.framework.TestCase.assertEquals
6+
import kotlinx.coroutines.test.runTest
7+
import okhttp3.OkHttpClient
8+
import org.junit.Before
9+
import org.junit.Test
10+
import retrofit2.Retrofit
11+
import retrofit2.converter.gson.GsonConverterFactory
12+
import java.util.concurrent.TimeUnit
13+
14+
/**
15+
* Network local unit test, which will execute on the development machine (host).
16+
*/
17+
class NetworkUnitTest {
18+
private lateinit var network: RetrofitPlaceAPI
19+
20+
// Default Latitude, Longitude
21+
private val defaultLatLng = "0.0, 0.0"
22+
// Default Place ID
23+
private val defaultPlaceID = "ChIJN1t_tDeuEmsRUsoyG83frY4"
24+
25+
@Before
26+
fun init() {
27+
val okHttpClient = OkHttpClient()
28+
.newBuilder()
29+
.callTimeout(Constants.TIMEOUT_SEC, TimeUnit.SECONDS)
30+
.readTimeout(Constants.TIMEOUT_SEC, TimeUnit.SECONDS)
31+
.writeTimeout(Constants.TIMEOUT_SEC, TimeUnit.SECONDS)
32+
.connectTimeout(Constants.TIMEOUT_SEC, TimeUnit.SECONDS)
33+
.build()
34+
35+
val retrofitInstance = Retrofit
36+
.Builder()
37+
.baseUrl(Constants.PLACE_API_BASE_URL)
38+
.client(okHttpClient)
39+
.addConverterFactory(GsonConverterFactory.create())
40+
.build()
41+
42+
network = retrofitInstance.create(RetrofitPlaceAPI::class.java)
43+
}
44+
45+
46+
@Test
47+
fun call_NearBySearch_GET_RESULT() = runTest {
48+
val response = network.getNearBySearch(
49+
latLng = defaultLatLng,
50+
radius = Constants.LOCATION_RADIUS,
51+
type = Constants.LOCATION_TYPE,
52+
apiKey = BuildConfig.PLACE_API_KEY
53+
)
54+
55+
assertEquals(200, response.code())
56+
}
57+
58+
@Test
59+
fun call_Detail_GET_RESULT() = runTest {
60+
val response = network.getDetails(
61+
placeID = defaultPlaceID,
62+
apiKey = BuildConfig.PLACE_API_KEY
63+
)
64+
65+
assertEquals(200, response.code())
66+
}
67+
}

0 commit comments

Comments
 (0)