-
Notifications
You must be signed in to change notification settings - Fork 46
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
[스캇] 1단계 자동 DI 미션 제출합니다 #10
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7f2127
feat : 안드로이드 수동 DI 구현
chws0508 234eba0
feat : Repository Test 작성
chws0508 d38f76e
refactor : 실수로 ViewModel에게 Impl 을 주입한걸 interface를 주입하도록 수정
chws0508 aa60410
feat : MainViewModel Test 구현
chws0508 3dcff5d
refactor : CartViewModel 에서 코루틴 적용한 것 롤백
chws0508 d81c2d4
feat : CartViewModel 테스트 구현
chws0508 48f3302
feat : CartActivityTest 테스트 구현
chws0508 803254b
feat : 자동 DI 구현
chws0508 488159a
refactor : CartRepositoryImplTest 수정
chws0508 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
app/src/test/java/woowacourse/shopping/data/CartRepositoryImplTest.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,47 @@ | ||
package woowacourse.shopping.data | ||
|
||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import woowacourse.shopping.repository.CartRepository | ||
import woowacourse.shopping.util.Dummy | ||
|
||
class CartRepositoryImplTest { | ||
private lateinit var cartRepository: CartRepository | ||
|
||
@Before | ||
fun setUp() { | ||
cartRepository = CartRepositoryImpl( | ||
Dummy.cartProducts.toMutableList(), | ||
) | ||
} | ||
|
||
@Test | ||
fun `모든 카트 상품들을 반환한다`() { | ||
// when | ||
val actual = cartRepository.getAllCartProducts() | ||
// then | ||
val expected = Dummy.cartProducts | ||
assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `카트 상품을 지울 수 있다`() { | ||
// when | ||
cartRepository.deleteCartProduct(0) | ||
// then | ||
val actual = cartRepository.getAllCartProducts() | ||
val expected = listOf(Dummy.cartProducts[1]) | ||
assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `카트 상품을 추가할 수 있다`() { | ||
// when | ||
cartRepository.addCartProduct(product = Dummy.product) | ||
// then | ||
val actual = cartRepository.getAllCartProducts() | ||
val expected = Dummy.cartProducts + Dummy.product | ||
assertEquals(expected, actual) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/test/java/woowacourse/shopping/data/ProductRepositoryImplTest.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,18 @@ | ||
package woowacourse.shopping.data | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import woowacourse.shopping.util.Dummy | ||
|
||
class ProductRepositoryImplTest { | ||
private val productRepository = ProductRepositoryImpl() | ||
|
||
@Test | ||
fun `모든 상품을 반환한다`() { | ||
// when | ||
val actual = productRepository.getAllProducts() | ||
// then | ||
val expected = Dummy.products | ||
assertEquals(expected, actual) | ||
} | ||
} |
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,43 @@ | ||
package woowacourse.shopping.util | ||
|
||
import woowacourse.shopping.model.Product | ||
|
||
object Dummy { | ||
|
||
val product = Product( | ||
name = "Inez Raymond", | ||
price = 1591, | ||
imageUrl = "https://www.google.com/#q=inceptos", | ||
) | ||
|
||
val cartProducts = listOf( | ||
Product( | ||
name = "Scott", | ||
price = 1234, | ||
imageUrl = "https://duckduckgo.com/?q=graeci", | ||
), | ||
Product( | ||
name = "Buna", | ||
price = 5678, | ||
imageUrl = "https://duckduckgo.com/?q=graeci", | ||
), | ||
) | ||
|
||
val products = listOf( | ||
Product( | ||
name = "우테코 과자", | ||
price = 10_000, | ||
imageUrl = "https://cdn-mart.baemin.com/sellergoods/api/main/df6d76fb-925b-40f8-9d1c-f0920c3c697a.jpg?h=700&w=700", | ||
), | ||
Product( | ||
name = "우테코 쥬스", | ||
price = 8_000, | ||
imageUrl = "https://cdn-mart.baemin.com/sellergoods/main/52dca718-31c5-4f80-bafa-7e300d8c876a.jpg?h=700&w=700", | ||
), | ||
Product( | ||
name = "우테코 아이스크림", | ||
price = 20_000, | ||
imageUrl = "https://cdn-mart.baemin.com/sellergoods/main/e703c53e-5d01-4b20-bd33-85b5e778e73f.jpg?h=700&w=700", | ||
), | ||
) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package woowacourse.shopping.model | ||
|
||
class Product(val name: String, val price: Int, val imageUrl: String) | ||
data class Product(val name: String, val price: Int, val imageUrl: String) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
개인적으로 이부분이 가독성이 떨어진다고 생각했는데요,
0번째 원소가 없어지면 1~마지막 일것이라고 생각했는데 cartProducts[1]이라서 다른 파일에서 가서 cartProducts가 무슨 리스트인지 확인을 해야했습니다.
확실히 파일을 분리한 스캇의 코드가 깔끔해 보이지만, 저는 가독성을 위해 테스트를 위한 dummy는 같은 테스트 파일 하단에 존재해야한다고 생각하는데 스캇의 생각은 어떠신가요?
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.
Dummy 파일의 세부 내용을 직접 확인해야하는 경우에는 확실히 링링의 말처럼 테스트 하단 파일에 존재하는 것이 맞다고 생각합니다! 하지만 Dummy 파일의 내용을 직접 확인하지 않아도 되고, 공통으로 쓰이는 데이터 같은 경우에는 파일을 따로 분리하여 공통으로 사용되게 하면 좋을 것 같네요!
그리고 다시 생각해보니, CartRepository 를 테스트하는 것인데, Dummy.cartProducts 를 이용하는 것도 잘못된 것 같네요!
수정한 파일 커밋입니다 !
커밋 링크