Skip to content

Commit 7055170

Browse files
oungsi2000m6z1
andcommitted
[쇼핑 주문 1,2 단계] 밀러 미션 제출합니다 (woowacourse#98)
* Squashed commit of the following: commit ee14a860ec9a0714f214fcd95f654211afad7d53 Author: m6z1 <[email protected]> Date: Mon May 26 17:25:13 2025 +0900 refactor: mock server 클래스 네이밍 수정 commit a4a475aa8a1513138ac0d1219e006db5e6cc59f1 Author: m6z1 <[email protected]> Date: Mon May 26 17:24:56 2025 +0900 test: mock 상품 서버 테스트 추가 commit 47fdb3bea0ee013cb424c87c8bfb8d30108956bc Author: m6z1 <[email protected]> Date: Mon May 26 16:38:17 2025 +0900 chore: 사용하지 않는 코드 제거 commit 612f085807c885699c164d20f6e86d17f7ed56c4 Author: m6z1 <[email protected]> Date: Mon May 26 16:35:51 2025 +0900 test: 변경된 프로덕션 코드에 테스트 성공하도록 수정 commit dca0b22d72d29978bc665ac0194982d1904bb39b Author: m6z1 <[email protected]> Date: Mon May 26 16:11:59 2025 +0900 refactor: 함수 분리 commit 01fd74e94b7c12be72e13f5ff8daa461208ede41 Author: m6z1 <[email protected]> Date: Mon May 26 16:03:38 2025 +0900 refactor: 상품 목록 뷰 수량 조절 컴포넌트 사용 commit 31531c70376089106aca19669d623c75212e3362 Author: m6z1 <[email protected]> Date: Mon May 26 15:22:53 2025 +0900 refactor: 불필요한 함수 제거 commit 6e28f6050542ccc04302c19cdac02c8bb59ffe98 Author: m6z1 <[email protected]> Date: Mon May 26 15:18:17 2025 +0900 feat: 상품 목록 값 서버 통신으로 호출 commit 42855097a4721063665b068c823ce32639837821 Author: m6z1 <[email protected]> Date: Mon May 26 15:17:41 2025 +0900 chore: 패키지 이동 commit 78818df44b0758dc9c5e82cabce440403f304780 Author: m6z1 <[email protected]> Date: Mon May 26 14:57:46 2025 +0900 build: 네트워크용 라이브러리 추가 commit caf311ff815614eb919d8cebcae31702122f7eee Author: m6z1 <[email protected]> Date: Mon May 26 13:51:22 2025 +0900 chore: 패키지 분리 commit ae13808677f08f12f8cbb510aeef10af0354e05e Author: m6z1 <[email protected]> Date: Mon May 26 13:40:08 2025 +0900 fix: 최근 본 상품 이전의 상품 개수 업데이트 안 되는 이슈 해결 commit f45a1c61953dd5883735ba1a56a92977ff20ed1b Author: m6z1 <[email protected]> Date: Mon May 26 13:21:57 2025 +0900 feat: 마지막으로 본 상품 페이지 뒤로가기 시 상품 목록 이동 구현 commit 5bf546fdf96a39ef84bfe6a64db5da86496aaa0f Author: m6z1 <[email protected]> Date: Mon May 26 04:27:51 2025 +0900 fix: 마지막에 본 상품 클릭 시 마지막에 본 상품 ui 출력되는 이슈 해결 commit e8fd2f41bb2f2397fcb25a4378815852ff5b7182 Author: m6z1 <[email protected]> Date: Mon May 26 04:04:52 2025 +0900 feat: 마지막으로 본 상품일 경우 마지막으로 본 상품 ui 가시성 처리 commit 8c46f764a2567fadf19dd33cafee52497a4ec9a6 Author: m6z1 <[email protected]> Date: Mon May 26 04:03:08 2025 +0900 feat: 상품 상세화면에서 마지막으로 본 상품 출력 로직 구현 commit b16d1ab30766be7ac144df73b7824837a69fcea7 Author: m6z1 <[email protected]> Date: Mon May 26 03:47:49 2025 +0900 refactor: string 리소스 추출 commit 66930ef84673dcd35a2e04e49f53c060d6a1052d Author: m6z1 <[email protected]> Date: Mon May 26 03:45:11 2025 +0900 feat: 앱 재시작돼도 최근 본 상품 목록 유지 commit ba7864091b772e7ee917f3b0e4152c12c844ffba Author: m6z1 <[email protected]> Date: Mon May 26 03:07:33 2025 +0900 refactor: RecyclerView 아이템 데코레이터 구현 commit 694ed96ee0250a214b1773d225731cde11e2c083 Author: m6z1 <[email protected]> Date: Mon May 26 03:02:10 2025 +0900 feat: 최근 본 상품 로직 구현 commit 10b2c41995678e2cd75cca6c5bf179da198c2731 Author: m6z1 <[email protected]> Date: Mon May 26 01:39:17 2025 +0900 chore: 불필요한 파일 제거 commit d83505db73294dbaba35f2501108bd217ace370e Author: m6z1 <[email protected]> Date: Mon May 26 01:39:12 2025 +0900 feat: 앱 재시작에도 상품 목록 장바구니 개수 유지 commit 28f983d287be72890bd3d2f99071ffb22b302cca Author: m6z1 <[email protected]> Date: Sun May 25 23:56:56 2025 +0900 feat: 앱 재시작에도 장바구니 데이터 유지 commit f9212ff04a70429d6cd5bfe9fe4296e8f94fea6e Author: m6z1 <[email protected]> Date: Sun May 25 23:56:41 2025 +0900 build: Room 라이브러리 버전 2.7.1 업데이트 commit 3884639a89d30be1804a6571705bb2782c4bcabf Author: m6z1 <[email protected]> Date: Sun May 25 23:56:15 2025 +0900 refactor: application class 생성 commit 534abd57fad0a7b502e4827aa31ba35648cab837 Author: m6z1 <[email protected]> Date: Sun May 25 19:02:09 2025 +0900 docs: 기능 요구 사항 정리 commit fea92920ee32b6cf5e39bb5e31ab3fc22ed81726 Author: m6z1 <[email protected]> Date: Sun May 25 18:56:01 2025 +0900 build: room 라이브러리 추가 commit 2d4262ce2b9a64af8433115c8c950051b66dec3c Author: m6z1 <[email protected]> Date: Sun May 25 15:12:43 2025 +0900 feat: 장바구니 화면에서 뒤로 갔을 때 상태 일치 로직 구현 commit 2c3f80de3ec329a009faf842b6eb436ac6d34c4c Author: m6z1 <[email protected]> Date: Sun May 25 14:16:38 2025 +0900 feat: 상품 상세 화면에서 뒤로 갔을 때 상태 일치 로직 구현 commit 57b84e929376b0f2dc80df52252a816ace74b2b4 Author: m6z1 <[email protected]> Date: Thu May 22 17:11:32 2025 +0900 feat: 장바구니에 담은 수량 조절 로직 구현 commit 609dffb3ffbc68b3c5dd0f461369c8793fba60c2 Author: m6z1 <[email protected]> Date: Thu May 22 16:58:09 2025 +0900 feat: 장바구니 상품 제거 / 장바구니 수량 빼는 로직 분리 commit 6753a2cca3abc0fb406b5c1721f0e2f1827f0915 Author: m6z1 <[email protected]> Date: Thu May 22 16:23:04 2025 +0900 feat: 장바구니 화면 수량 별 가격 출력 구현 commit f402d7cd9223d0c08d6433c8e25089b7e5e20181 Author: m6z1 <[email protected]> Date: Thu May 22 16:22:45 2025 +0900 refactor: 장바구니 상품 조회 반환 타입 수정 commit 4a0f8bb5ae5b3e600a2032e446f96e440248c60e Author: m6z1 <[email protected]> Date: Thu May 22 15:46:49 2025 +0900 feat: 상품 상세 화면 수량만큼 선택한 총 가격 출력 구현 commit eeb7c0fb2991195183e81e750b079993a5dcae2a Author: m6z1 <[email protected]> Date: Thu May 22 15:40:18 2025 +0900 feat: 상품 상세 화면 수량 조절 버튼 구현 commit a6cc3d7bee32fe9fbd1e17aff9d19b65133b8251 Author: m6z1 <[email protected]> Date: Thu May 22 15:40:08 2025 +0900 feat: 상품 수량 공용 컴포넌트 Ui 구현 commit d4d75847633f6508b3246ef589c1088300fa2f11 Author: m6z1 <[email protected]> Date: Thu May 22 13:34:51 2025 +0900 feat: 상품 목록 뷰 장바구니 로직 추가 - 각 상품에서 + - 버튼을 통해 수량을 조절할 수 있다. - 장바구니에 담근 총 수량이 보인다. commit 967db9894b60d73b7ba3513e87862d85abccab9f Author: m6z1 <[email protected]> Date: Wed May 21 17:17:17 2025 +0900 feat: 각 상품에 + 버튼 ui 구현 commit 90a01e7aeb3560e84c5237fbdaf0dd5464f1b7f6 Author: m6z1 <[email protected]> Date: Wed May 21 13:41:47 2025 +0900 refactor: 함수 네이밍 명시적으로 수정 commit 85b96fc36d86051debe34415217b798fe4a60f04 Author: m6z1 <[email protected]> Date: Wed May 21 13:37:05 2025 +0900 refactor: 중복되는 값 변수에 할당 - ProductsViewModel에서 중복되는 라이브 데이터 값 할당 후 사용 commit 83f3c2baaa82e81d79343f8d24a4a13fd5435793 Author: m6z1 <[email protected]> Date: Wed May 21 13:22:53 2025 +0900 refactor: 상품 목록 아이템 추가 함수 네이밍 수정 commit 93c65d1e824bc4b8aa22cd8236a6bdff7cada002 Author: m6z1 <[email protected]> Date: Wed May 21 13:21:09 2025 +0900 chore: activity exported 속성 수정 commit 5834af9e3b78e5857db83d2b8b6be782278dc8f1 Author: m6z1 <[email protected]> Date: Wed May 21 13:18:21 2025 +0900 refactor: 상품 목록 조회 호출 로직 수정 commit ad2e4ca0075a301fee2cea0a6d01f46020a4022e Author: m6z1 <[email protected]> Date: Wed May 21 11:26:17 2025 +0900 refactor: result 콜백 매개변수 네이밍 수정 commit a6fbdb0403a5cf770a713656f27c4681cf918724 Author: m6z1 <[email protected]> Date: Wed May 21 11:23:13 2025 +0900 docs: 기능 요구 사항 정리 commit 519909ad15a249eea2d31c129b39a9bf8398fdb1 Author: Son Myeongji <[email protected]> Date: Tue May 20 20:13:07 2025 +0900 [쇼핑 장바구니 1, 2단계] 뭉치 미션 제출합니다. (woowacourse#101) * docs: 기능 요구 사항 작성 * build: 데이터 바인딩 추가 * feat: Product 생성 * feat: 상품 목록 화면에서 행당 2개의 상품을 출력 * chore: 패키지 분리 * build: Glide 라이브러리 추가 * chore: 더미 데이터 수정 * feat: ProductUrls 구현 * build: kapt 추가 * feat: BindingAdapter setImageUrl 구현 * feat: 인터넷 권한 추가 * feat: 이미지 바인딩 어댑터 사용 * chore: BindingAdapter 패키지 이동 * feat: 아이템 간 마진 조정 * chore: 메뉴 아이콘들 추가 * feat: 앱 테마 NoActionBar 수정 * feat: 상품 목록 페이지 toolbar 구현 * feat: color 리소스 이름 변경 * feat: 장바구니 화면 구현 * feat: 장바구니 버튼 클릭 이벤트 구현 * feat: 뒤로 가기 버튼 클릭 이벤트 구현 * feat: 상품 상세 화면 구현 * chore: 패키지 이동 * feat: Product 직렬화 * feat: 상품 클릭 시 상품 상세로 이동 * refactor: 에러 메시지 String 리소스 추출 * feat: 상품 상세 화면 X 버튼 클릭 이벤트 구현 * chore: 패키지 분리 * feat: 장바구니 저장소 구현 * feat: 장바구니 추가 기능 구현 * feat: 상품 목록 저장소 구현 * feat: 상품 목록 뷰모델 구현 * feat: 장바구니 뷰모델 구현 * feat: 장바구니 상품 삭제 구현 * docs: 기능 요구 사항 작성 * feat: 상품 목록 더보기 구현 * refactor: 함수 이름 변경 * feat: 장바구니 페이지네이션 뷰 구현 * refactor: 팩토리 메서드 네이밍 수정 * feat: 장바구니 페이지네이션 뷰홀더 추가 * feat: 페이지네이션 구현 * feat: 페이지에 5개씩 가져오도록 구현 * feat: 장바구니 페이지네이션 구현 * docs: 기능 요구 사항 체크리스트 업데이트 * feat: 페이지네이션 아이템 가시성 처리 * refactor: 상품 목록 뷰 멀티 뷰 타입으로 개선 * test: ProductsViewModel 테스트 추가 등록된 상품들을 가져올 수 있다 * test: ShoppingCartViewModel 테스트 추가 - 장바구니에 담은 상품들을 보여준다 - 제거하고 싶은 상품을 장바구니에서 삭제할 수 있다 - 장바구니의 다음 페이지 정보를 확인할 수 있다 - 장바구니의 이전 페이지 정보를 확인할 수 있다 * refactor: 매퍼 함수 위치 수정 * refactor: 중복되는 layoutManager 설정 제거 * refactor: 클릭 리스너 interface 네이밍 수정 * refactor: 상품 상세 뷰 스크롤 되도록 수정 * refactor: repository 비동기 콜백 구조로 수정 * refactor: 불필요한 함수 호출 로직 개선 * refactor: 사용하지 않는 데이터바인딩 변수 제거 * refactor: 함수 분리 * feat: 장바구니 마지막 페이지 데이터 없을 경우 이전 페이지로 이동하도록 수정 * fix: 장바구니 무한 호출 이슈 해결 * refactor: 더보기 버튼 가시성 로직 수정 * refactor: 페이지네이션 여부 판단 책임 뷰모델로 이동 * refactor: 무한스크롤 여부 판단 책임 뷰모델로 이동 * refactor: Product 객체 생성자에 imageUrl 추가 * chore: view/common 패키지 분리 * refactor: 휘발성 이벤트 SingleLiveData 적용 * refactor: 화면 회전 시 뷰모델 호출 횟수 개선 * chore: 코드 포맷팅 * refactor: 상품 목록 RecyclerView 데이터 수정 로직 개선 * fix: 더보기 버튼 클릭 시 상품 목록 데이터 호출되지 않는 이슈 해결 * build: corecore-testing 라이브러리 추가 * test: 뷰모델 테스트 위한 확장함수 구현 * test: ProductsViewModel 테스트 추가 * test: TestFixture 매개변수의 값에 따라 생성될 수 있도록 수정 * test: ShoppingCartViewModel 테스트 추가 * test: ProductDetailViewModel 테스트 추가 * test: ProductDetail UI 테스트 추가 --------- Co-authored-by: Giovanni Junseo Kim <[email protected]> commit e31149b Author: woowahan-dino <[email protected]> Date: Mon Apr 7 14:31:36 2025 +0900 build: upgrade to kotlin 2.1.0 and android gradle plugin 8.5.2 commit 281c081 Author: woowahan-pjs <[email protected]> Date: Fri Apr 12 12:00:25 2024 +0900 build: upgrade to android gradle plugin 8.3.1 and add junit 5 commit 186fb7f Author: woowahan-pjs <[email protected]> Date: Mon May 8 14:05:24 2023 +0900 feat: set up the project commit c0c96e0 Author: 박재성 <[email protected]> Date: Mon Apr 10 20:30:26 2023 +0900 Initial commit * docs: 기능 요구 사항 정리 * build: preferences datastore 라이브러리 추가 * chore: storage 네이밍 수정 * feat: 사용자 인증 repository 구현 * feat: 사용자의 인증 정보를 저장 * chore: 코드 포맷팅 * build: kotlin serialization 의존성 추가 * build: retrofit 의존성 추가 * feat: api client 구현 * feat: 상품 목록 호출 api 생성 * feat: 상품 목록 서버 통신 구현 * build: serialization converter 의존성 추가 * refactor: converter gson 에서 json 으로 변경 * feat: 상품 목록 서버 호출 로직 구현 * feat: 서버에서 가져온 장바구니 총 수량을 표시 * feat: ktlint Format * feat: 장바구니에 아이템 추가 api 구현 * feat: 장바구니 수량 수정 api 구현 * docs: 기능 요구 사항 체크리스트 업데이트 * feat: 상품 상세 정보 api 연동 * refactor: ResponseDto 네이밍 수정 * feat: 장바구니 목록 api 연동 * fix: 쇼핑카트 아이템 추가 안 되는 이슈 해결 * refactor: ui 아이템 수량 observable 인터페이스 상속 * fix: 수량 변경 path 값 수정 * fix: onPlusShoppingCartClick 수정 잘못된 뷰모델 메서드 호출 minus -> add * fix: 잘못된 retrofit convertertype 수정 * fix: 수량 조절 api 로직 수정 * fix: 장바구니 캐시 로직 제거 * fix: +버튼을 눌렀을 때 장바구니 서버에 반영 안되는 문제 해결 * fix: 장바구니 수량 가져와 상품 목록 수량 보이도록 수정 * fix: 다른 화면에서 다시 상품 목록 돌아왔을 때 장바구니 수량 업데이트 로직 수정 * feat: 서버의 장바구니 아이템 삭제 기능 구현 * feat: 상품 목록 뷰 스켈레톤 ui 적용 * feat: 상품 목록 뷰 스켈레톤 ui 구현 * feat: 장바구니 목록 뷰 스켈레톤 ui 구현 * refactor: 스켈레톤 layout 네이밍 수정 * fix: 더보기 버튼 데이터 불러와지지 않는 이슈 해결 * refactor: 불필요한 장바구니 local db 제거 * fix: 상품 상세화면으로 cartId 및 수량 넘기는 로직 수정 * fix: 상품 상세 화면 수량 조절 로직 구분 * fix: 수량 업데이트 되지 않는 현상 해결 * chore: 상품 상세 화면에서 최근 본 상품 클릭 리스너 제거 * docs: step2 기능 요구사항 작성 * feat: 장바구니 주문하기 ui 구현 * feat: 장바구니 추천 페이지 ui 구현 * feat: 장바구니 추천 상품 아이템 구현 * feat: 장바구니에서 선택한 총 가격과 개수 구현 * fix: 장바구니에서 수량 변경 시 체크 상태가 소실되는 문제 해결 * feat: 전체 장바구니 선택 버튼 로직 구현 * fix: 최근 본 상품 목록 추가되지 않는 이슈 해결 * refactor: 장바구니 페이지 무한스크롤로 수정 * fix: 장바구니 목록 보이지 않는 현상 해결 * fix: 장바구니 무한스크롤 로직 수정 * fix: 무한스크롤 아이템 추가 로직 수정 * fix: 무한스크롤 판단 여부 수정 * fix: 장바구니 호출 size 수정 * feat: Product Category 추가 * fix: 상품 목록 뷰 최근 본 상품 없을 때 값이 덮어씌워지는 이슈 해결 * feat: 장바구니 추천 화면에서 주문하기 위해 선택한 아이템 받아 총 가격 및 총 개수 출력 * feat: 상품 추천 알고리즘 구현 * fix: 가장 최근 본 상품 화면에서 최근 본 상품 뜨는 로직 수정 * fix: 최근 본 상품 저장 로직 수정 * refactor: 상품 목록 뷰 ListAdapter로 개선 * feat: 추천 상품 수량 추가 버튼 구현 * fix: increaseQuantity 수량 증가 버튼 클릭 시 장바구니 호출 로직 수정 * fix: 추천 상품 수량 중복으로 추가되는 현상 해결 * fix: 추천 상품 장바구니 수량 감소 버튼 로직 수정 * feat: http loggin interceptor 추가 * feat: 추천 상품 수량 장바구니 추가 로직 구현 * feat: 추천 상품에서 뒤로갔을 때 장바구니 업데이트 로직 추가 * refactor: 장바구니 목록 ListAdapter로 수정 * chore: .gitkeep 파일 제거 * feat: 장바구니에 선택된 상품이 없으면 주문하기 버튼 비활성화 * chore: ktlint 포맷팅 * test: 통과하지 않는 테스트 제거 * refactor: ProductsViewModel 코루틴으로 변경 * refactor: ShoppingCartViewModel 코루틴으로 변경 * fix: 장바구니 상품이 삭제되면 모두 로드가 안되는 버그 해결 * refactor: 주문정보 표시 로직 orderBarViewModel로 이동 * refactor: dto 사용하지 않는 필드 제거 * refactor: dto 중첩 Ktlint Format * refactor: include 감싸는 Layout 제거 * refactor: 사용되지 않는 view 제거 * refactor: isChecked xml에서 인자 제거 * refactor: ShoppingCartRecommendViewModel 로직 간결하게 * fix: 추천 상품에서 장바구니로 돌아오면 장바구니가 중복되는 문제 해결 * refactor: data layor에서 가져온 값 뷰모델에서 사용 * refactor: LiveData.map 확장함수 사용 * fix: 화면 회전 시 결제 금액 정보가 날아가는 문제 해결 * fix: 장바구니 화면 회전 시 중복된 데이터 추가 버그 해결 * refactor: ListAdapter 로 변경 * refactor: 사용되지 않는 장바구니 pagination view 제거 * refactor: 단방향 이벤트 흐름 반영 * refactor: 스켈레톤ui 데이터바인딩으로 전환 * refactor: 뷰모델 초기화 생성자에서 하도록 변경 * refactor: Dto postfix 제거 * refactor: 명시적으로 thread join으로 변경 * refactor: 리사이클러 뷰 아이템 api 로딩상태 관리 * test: ProductsActivity 테스트 작성 * test: ProductsActivity 테스트 수정 * test: ProductsDetailActivity 테스트 작성 * test: ShoppingCartActivity 테스트 작성 * test: ShoppingCartRecommend 테스트 작성 --------- Co-authored-by: m6z1 <[email protected]>
1 parent f59f034 commit 7055170

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package woowacourse.shopping.data
2+
3+
import okhttp3.OkHttpClient
4+
import okhttp3.Request
5+
import org.assertj.core.api.Assertions.assertThat
6+
import org.junit.jupiter.api.AfterEach
7+
import org.junit.jupiter.api.Test
8+
import woowacourse.shopping.data.product.remote.MockProductServer
9+
10+
class MockProductServerTest {
11+
private val mockProductServer = MockProductServer()
12+
13+
@Test
14+
fun `마지막 상품 id 와 가져올 개수를 통해 상품 목록을 불러온다`() {
15+
// given:
16+
mockProductServer.start(1234)
17+
val client = OkHttpClient()
18+
19+
val request =
20+
Request
21+
.Builder()
22+
.url("http://localhost:1234/products?lastProductId=&size=3")
23+
.build()
24+
25+
// when:
26+
val response = client.newCall(request).execute()
27+
28+
// then:
29+
assertThat(response.code).isEqualTo(200)
30+
assertThat(response.body?.string()).isEqualTo(
31+
"""
32+
[
33+
{
34+
"id": 1,
35+
"name": "럭키",
36+
"price": 4000,
37+
"imageUrl": "https://i.namu.wiki/i/ExNTyOB5363wFnhGLSfRPOSj9G5VwSQiISkjICuIVI-8S8djFN8cJLB44Mb7jzqQMu-8OJxtuPTmE3FLkq4ebg.webp"
38+
},
39+
{
40+
"id": 2,
41+
"name": "아이다",
42+
"price": 700,
43+
"imageUrl": "https://i.namu.wiki/i/NHwDBf6H1jECcAe5OMq2EGGW5UQkt1gYITM9usAr0LZCvlsHl7h69IgP-xU2jKK-GnF2M3ZDHBYx6qJwI8rb4A.webp"
44+
},
45+
{
46+
"id": 3,
47+
"name": "설백",
48+
"price": 1000,
49+
"imageUrl": "https://i.namu.wiki/i/JYqF9aBMf6foB0HMqfc8oZVXlUJjCUrK6W_5Q1Prk5YM2VA7nmIv57EVRDFPaQ2CKQubfsg-3BSgxt_6GXoMqw.webp"
50+
}
51+
]
52+
""".allSpaceTrim(),
53+
)
54+
55+
mockProductServer.shutDown()
56+
}
57+
58+
@Test
59+
fun `잘못된 url 로 호출 시 응답 코드 404를 반환한다`() {
60+
// given:
61+
mockProductServer.start(1234)
62+
val client = OkHttpClient()
63+
64+
val request =
65+
Request
66+
.Builder()
67+
.url("http://localhost:1234/product")
68+
.build()
69+
70+
// when:
71+
val response = client.newCall(request).execute()
72+
73+
// then:
74+
assertThat(response.code).isEqualTo(404)
75+
}
76+
77+
private fun String.allSpaceTrim(): String = replace("\\s".toRegex(), "")
78+
79+
@AfterEach
80+
fun tearDown() {
81+
mockProductServer.shutDown()
82+
}
83+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package woowacourse.shopping.view.common
2+
3+
import androidx.arch.core.executor.ArchTaskExecutor
4+
import androidx.arch.core.executor.TaskExecutor
5+
import org.junit.jupiter.api.extension.AfterEachCallback
6+
import org.junit.jupiter.api.extension.BeforeEachCallback
7+
import org.junit.jupiter.api.extension.ExtensionContext
8+
9+
class InstantTaskExecutorExtension :
10+
BeforeEachCallback,
11+
AfterEachCallback {
12+
override fun beforeEach(context: ExtensionContext?) {
13+
ArchTaskExecutor.getInstance().setDelegate(
14+
object : TaskExecutor() {
15+
override fun executeOnDiskIO(runnable: Runnable) {
16+
runnable.run()
17+
}
18+
19+
override fun postToMainThread(runnable: Runnable) {
20+
runnable.run()
21+
}
22+
23+
override fun isMainThread(): Boolean = true
24+
},
25+
)
26+
}
27+
28+
override fun afterEach(context: ExtensionContext?) {
29+
ArchTaskExecutor.getInstance().setDelegate(null)
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package woowacourse.shopping.view.common
2+
3+
import androidx.lifecycle.LiveData
4+
import androidx.lifecycle.Observer
5+
import java.util.concurrent.CountDownLatch
6+
import java.util.concurrent.TimeUnit
7+
import java.util.concurrent.TimeoutException
8+
9+
fun <T> LiveData<T>.getOrAwaitValue(
10+
time: Long = 2,
11+
timeUnit: TimeUnit = TimeUnit.SECONDS,
12+
): T {
13+
var data: T? = null
14+
val latch = CountDownLatch(1)
15+
val observer =
16+
object : Observer<T> {
17+
override fun onChanged(value: T) {
18+
data = value
19+
latch.countDown()
20+
this@getOrAwaitValue.removeObserver(this)
21+
}
22+
}
23+
24+
this.observeForever(observer)
25+
26+
if (!latch.await(time, timeUnit)) {
27+
throw TimeoutException("LiveData value was never set.")
28+
}
29+
30+
@Suppress("UNCHECKED_CAST")
31+
return data as T
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package woowacourse.shopping.view.shoppingCart
2+
3+
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
4+
import io.mockk.clearAllMocks
5+
import io.mockk.mockk
6+
import org.junit.Rule
7+
import org.junit.jupiter.api.AfterEach
8+
import org.junit.jupiter.api.BeforeEach
9+
import org.junit.jupiter.api.extension.ExtendWith
10+
import woowacourse.shopping.data.shoppingCart.repository.ShoppingCartRepository
11+
import woowacourse.shopping.view.common.InstantTaskExecutorExtension
12+
import woowacourse.shopping.view.shoppingCart.viewModel.ShoppingCartViewModel
13+
14+
@ExtendWith(InstantTaskExecutorExtension::class)
15+
class ShoppingCartViewModelTest {
16+
@get:Rule
17+
val instantExecutorRule = InstantTaskExecutorRule()
18+
19+
private lateinit var shoppingCartViewModel: ShoppingCartViewModel
20+
private lateinit var shoppingCartRepository: ShoppingCartRepository
21+
22+
@BeforeEach
23+
fun setUp() {
24+
shoppingCartRepository = mockk()
25+
shoppingCartViewModel = ShoppingCartViewModel(shoppingCartRepository)
26+
}
27+
28+
@AfterEach
29+
fun tearDown() {
30+
clearAllMocks()
31+
}
32+
}

0 commit comments

Comments
 (0)