Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step1: GitHub(모듈 분리) #97

Merged
merged 3 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
kotlin("android")
kotlin("kapt")
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
}

android {
Expand All @@ -20,7 +21,7 @@ android {
}

buildTypes {
getByName("release") {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
Expand Down Expand Up @@ -48,9 +49,10 @@ dependencies {
implementation("com.google.android.material:material:1.7.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.fragment:fragment-ktx:1.5.5")
implementation(project(":core:data"))

testImplementation("junit:junit:4.13.2")
testImplementation("com.google.truth:truth:1.1.3")
testImplementation("com.google.truth:truth:1.1.4")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/java/camp/nextstep/edu/github/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package camp.nextstep.edu.github

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
}
17 changes: 0 additions & 17 deletions app/src/test/java/camp/nextstep/edu/github/ExampleUnitTest.kt

This file was deleted.

3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Configs.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
object Version {
const val androidGradlePlugin = "7.4.0"
const val kotlin = "1.8.0"
const val kotlin = "1.9.0"
const val compileSdk = 33
const val minSdk = 26
const val targetSdk = 33
const val retrofit = "2.9.0"
}
1 change: 1 addition & 0 deletions core/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
21 changes: 21 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("kotlin")
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Version.kotlin}")
implementation("com.squareup.retrofit2:retrofit:${Version.retrofit}")
implementation("com.squareup.retrofit2:converter-gson:${Version.retrofit}")
implementation(project(":core:domain"))

testImplementation("junit:junit:4.13.2")
testImplementation("com.google.truth:truth:1.1.4")
testImplementation("com.squareup.okhttp3:mockwebserver:4.11.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
}
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>
}
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()
}
}
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)
}
}
4 changes: 4 additions & 0 deletions core/data/src/test/resources/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{
"full_name": "nextStep",
"description": "android-github"
}]
1 change: 1 addition & 0 deletions core/domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
15 changes: 15 additions & 0 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("kotlin")
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
implementation("com.google.code.gson:gson:2.10.1")

testImplementation("junit:junit:4.13.2")
testImplementation("com.google.truth:truth:1.1.4")
}
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
)
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>
}
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include(":app")
rootProject.name = "android-github"
include(":app")
include(":core:domain")
include(":core:data")