-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8531d53
commit 47f50aa
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
core/data/src/main/java/camp/nextstep/edu/github/data/network/GitHubService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package camp.nextstep.edu.github.data.network | ||
|
||
import camp.nextstep.edu.github.domain.GithubRepository | ||
import retrofit2.http.GET | ||
|
||
interface GitHubService { | ||
@GET("/repositories") | ||
suspend fun getRepositories(): List<GithubRepository> | ||
} |
12 changes: 12 additions & 0 deletions
12
.../data/src/main/java/camp/nextstep/edu/github/data/network/GithubRepositoriesDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package camp.nextstep.edu.github.data.network | ||
|
||
import camp.nextstep.edu.github.domain.GithubRepository | ||
import camp.nextstep.edu.github.domain.network.GitHubDataSource | ||
|
||
internal class GithubRepositoriesDataSource( | ||
private val gitHubService: GitHubService | ||
) : GitHubDataSource { | ||
override suspend fun fetchRepositories(): List<GithubRepository> { | ||
return gitHubService.getRepositories() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...a/src/test/java/camp/nextstep/edu/github/data/network/GithubRepositoriesDataSourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package camp.nextstep.edu.github.data.network | ||
|
||
import camp.nextstep.edu.github.domain.GithubRepository | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.test.runTest | ||
import okhttp3.OkHttpClient | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.io.File | ||
import java.util.concurrent.TimeUnit | ||
|
||
class GithubRepositoriesDataSourceTest { | ||
private lateinit var mockWebServer: MockWebServer | ||
private lateinit var api: GitHubService | ||
private lateinit var dataSource: GithubRepositoriesDataSource | ||
|
||
private val client = OkHttpClient.Builder() | ||
.connectTimeout(1, TimeUnit.SECONDS) | ||
.readTimeout(1, TimeUnit.SECONDS) | ||
.writeTimeout(1, TimeUnit.SECONDS) | ||
.build() | ||
|
||
@Before | ||
fun setUp() { | ||
mockWebServer = MockWebServer() | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
mockWebServer.shutdown() | ||
} | ||
|
||
@Test | ||
fun `GitHub repository들을 불러옴`() = runTest { | ||
api = Retrofit.Builder() | ||
.baseUrl(mockWebServer.url("")) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(GitHubService::class.java) | ||
val body = File("src/test/resources/response.json").readText() | ||
val response = MockResponse().setBody(body).setResponseCode(200) | ||
mockWebServer.enqueue(response) | ||
dataSource = GithubRepositoriesDataSource(api) | ||
val actual = dataSource.fetchRepositories()[0] | ||
val expected = GithubRepository("nextStep", "android-github") | ||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `GitHub repository 실제 데이터 체크`() = runTest { | ||
api = Retrofit.Builder() | ||
.baseUrl(mockWebServer.url("https://api.github.com/")) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(GitHubService::class.java) | ||
dataSource = GithubRepositoriesDataSource(api) | ||
val actual = dataSource.fetchRepositories() | ||
assertThat(actual).hasSize(100) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[{ | ||
"full_name": "nextStep", | ||
"description": "android-github" | ||
}] |
9 changes: 9 additions & 0 deletions
9
core/domain/src/main/java/camp/nextstep/edu/github/domain/GithubRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package camp.nextstep.edu.github.domain | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class GithubRepository( | ||
@SerializedName("full_name") | ||
val fullName: String, | ||
val description: String | ||
) |
7 changes: 7 additions & 0 deletions
7
core/domain/src/main/java/camp/nextstep/edu/github/domain/network/GitHubDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package camp.nextstep.edu.github.domain.network | ||
|
||
import camp.nextstep.edu.github.domain.GithubRepository | ||
|
||
interface GitHubDataSource { | ||
suspend fun fetchRepositories(): List<GithubRepository> | ||
} |