-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์ ๋์๋!
2๋จ๊ณ ๊ณ ์ํ์
จ์ต๋๋ค!
์์์ฑํด์ฃผ์
จ๋ค์!
๋ช๊ฐ์ง ๊ณ ๋ฏผํ ๋ฒํ ํฌ์ธํธ๋ค ์ฝ๋ฉํธ๋ก ๋จ๊ฒผ์ผ๋, ํ์ธํด์ฃผ์ธ์!
๋ณ๊ฒฝ์ฌํญ์ ๋ค์ ๋ฏธ์
์งํํ๋ฉด์ ์ ์ฉํด์ฃผ์ธ์ ๐
internal inline fun <T> networkResult(transform: () -> T): Result<T> = try { | ||
Result.Success(transform.invoke()) | ||
} catch (e: Exception) { | ||
Result.Error(e) | ||
} |
There was a problem hiding this comment.
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/" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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ํ์ผ์ ํ์ฉํด๋ด๋ ์ข์์!
์๋ ํ์ธ์ ๋ฆฌ๋ทฐ์ด๋.
2๋จ๊ณ ๋ฏธ์ ๋ฆฌ๋ทฐ ์์ฒญ๋๋ฆฝ๋๋ค.
MockServer๋ฅผ ๋ชจ๋๋ก ์์ฑํด์ ๋ฐ๋ก ๊ด๋ฆฌํ ๊ฒฝ์ฐ๋ ํ ์คํธ ๋ฒ์๊ฐ ๋์ ๋ ์ฌ์ฉํ ์ ์์๊น์?
์ธ์ ๋ชจ๋๋ก ๊ด๋ฆฌํด์ผ ํจ์จ์ ์ธ์ง ๊ถ๊ธํฉ๋๋ค.
์ด๋ฒ ๋ฏธ์ TODO