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

๐Ÿš€ 2๋‹จ๊ณ„ - GitHub(HTTP) #105

Merged
merged 13 commits into from
Sep 1, 2023

Conversation

KwonDae
Copy link

@KwonDae KwonDae commented Aug 31, 2023

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜.
2๋‹จ๊ณ„ ๋ฏธ์…˜ ๋ฆฌ๋ทฐ ์š”์ฒญ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

MockServer๋ฅผ ๋ชจ๋“ˆ๋กœ ์ƒ์„ฑํ•ด์„œ ๋”ฐ๋กœ ๊ด€๋ฆฌํ•  ๊ฒฝ์šฐ๋Š” ํ…Œ์ŠคํŠธ ๋ฒ”์œ„๊ฐ€ ๋„“์„ ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?
์–ธ์ œ ๋ชจ๋“ˆ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํšจ์œจ์ ์ธ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฒˆ ๋ฏธ์…˜ TODO

  • Repository ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ธฐ๋Šฅ์€ data ๋ชจ๋“ˆ์— ๊ตฌํ˜„๋˜์–ด์•ผ ํ•œ๋‹ค. 3b2fdcd, 0c87b22
  • data ๋ชจ๋“ˆ์˜ ๊ตฌํ˜„์ฒด๋Š” ๋ชจ๋‘ internal class๋กœ ์„ ์–ธํ•œ๋‹ค. 3b2fdcd
  • HTTP ์š”์ฒญ์„ ํ†ตํ•ด ๊ฐ€์ ธ์˜ค๋Š” ๊ตฌํ˜„์ฒด์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ, OkHttp MockWebServer ์ด์šฉ. 75765ee

Copy link

@namjackson namjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•ˆ๋…•ํ•˜์„ธ์š” ๋Œ€์›๋‹˜!
2๋‹จ๊ณ„ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!
์ž˜์ž‘์„ฑํ•ด์ฃผ์…จ๋„ค์š”!
๋ช‡๊ฐ€์ง€ ๊ณ ๋ฏผํ• ๋ฒ•ํ•œ ํฌ์ธํŠธ๋“ค ์ฝ”๋ฉ˜ํŠธ๋กœ ๋‚จ๊ฒผ์œผ๋‹ˆ, ํ™•์ธํ•ด์ฃผ์„ธ์š”!
๋ณ€๊ฒฝ์‚ฌํ•ญ์€ ๋‹ค์Œ ๋ฏธ์…˜ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์ ์šฉํ•ด์ฃผ์„ธ์š” ๐Ÿ˜„

Comment on lines +10 to +14
internal inline fun <T> networkResult(transform: () -> T): Result<T> = try {
Result.Success(transform.invoke())
} catch (e: Exception) {
Result.Error(e)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธฐ์กด์— ์กด์žฌํ•˜๋Š” runCatching ์™€ ๋™์ผํ•œ ๊ตฌ์กฐ๋„ค์š”!
๊ตณ์ด ์ƒˆ๋กœ ๋งŒ๋“คํ•„์š”๋Š” ์—†์„๊ฑฐ๊ฐ™์•„์š”!

import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory

const val BASE_URL = "https://api.github.com/"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™ธ๋ถ€์—์„œ ๋…ธ์ถœ๋˜๊ธฐ๋ณด๋‹ค ๋‚ด๋ถ€์ ์œผ๋กœ๋งŒ ํ™œ์šฉ๋˜๋„ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”!


const val BASE_URL = "https://api.github.com/"

internal object RetrofitNetwork {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrofit์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๋„คํŠธ์›Œํฌ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ๋„ค์ด๋ฐ๋„ ๋ณ€๊ฒฝํ•ด์•ผํ• ๊นŒ์š”?
์ข€๋” ์ถ”์ƒ์ ์ธ ๋„ค์ด๋ฐ์„ ์‚ฌ์šฉํ•ด๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š”

}

@Test
fun `test_json_์š”์ฒญ`() = runTest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜๋ฏธ์žˆ๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ์ž‘์„ฑํ•ด๋„ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”!

}

@Test
fun `test_json_์š”์ฒญ2`() = runTest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ค‘๋ณต๋˜์„œ ๋ถˆํ•„์š”ํ•œ ํ…Œ์ŠคํŠธ ๊ฐ™์•„์š”!
์ฐจ๋ผ๋ฆฌ emptyList ๊ฐ™์€ ์ผ€์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

@Test
fun `test_json_์š”์ฒญ`() = runTest {
// given
val response = MockResponse().setBody(File("src/test/resources/repositories.json").readText())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/test/resources/repositories/200.json
src/test/resources/repositories/404.json
src/test/resources/repositories/๏ฟฝemptyList.json

๊ฐ™์ด ํ…Œ์ŠคํŠธ๋ณ„๋กœ ์—ฌ๋Ÿฌ ์ผ€์ด์Šค์˜ jsonํŒŒ์ผ์„ ํ™œ์šฉํ•ด๋ด๋„ ์ข‹์•„์š”!

@namjackson namjackson merged commit 67ec1bf into next-step:kwondae Sep 1, 2023
1 check passed
@KwonDae KwonDae deleted the step2 branch September 1, 2023 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants