Skip to content

[Koin Project][Chore] DiningRepository UseCase 단위 테스트 추가#1289

Closed
kongwoojin wants to merge 2 commits intodevelopfrom
chore/#1288-add-dining-usecase-test
Closed

[Koin Project][Chore] DiningRepository UseCase 단위 테스트 추가#1289
kongwoojin wants to merge 2 commits intodevelopfrom
chore/#1288-add-dining-usecase-test

Conversation

@kongwoojin
Copy link
Member

@kongwoojin kongwoojin commented Mar 1, 2026

PR 개요

이슈 번호: #1288

PR 체크리스트

  • Code convention을 잘 지켰나요?
  • Lint check를 수행하였나요?
  • Assignees를 추가했나요?

작업사항

  • 버그 수정
  • 신규 기능
  • 코드 스타일 수정 (포맷팅 등)
  • 리팩토링 (기능 수정 X, API 수정 X)
  • 기타

작업사항의 상세한 설명

DiningRepository 관련 UseCase 단위 테스트 추가

  • FakeDiningRepository 추가
  • GetDiningUseCaseTest 추가 (4개 테스트)
  • GetNotOperationFilteredDiningUseCaseTest 추가 (7개 테스트)

논의 사항

스크린샷

추가내용

  • develop, sprint 브랜치를 향하고 있습니다
  • production 브랜치를 향하고 있습니다

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for dining use cases: normal operations, filtering logic, empty-state and error handling, and edge cases to ensure reliability.
  • Test Utilities
    • Added an in-memory test double to simulate dining data and optional failure scenarios for deterministic testing.

Add FakeDiningRepository, GetDiningUseCaseTest,
and GetNotOperationFilteredDiningUseCaseTest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kongwoojin kongwoojin requested a review from a team as a code owner March 1, 2026 11:40
@kongwoojin kongwoojin self-assigned this Mar 1, 2026
@github-actions github-actions bot requested review from KYM-P and TTRR1007 March 1, 2026 11:40
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11a7a8d and bf6f66f.

📒 Files selected for processing (1)
  • domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt

📝 Walkthrough

Walkthrough

Adds a fake Dining repository for tests and two test suites covering GetDiningUseCase and GetNotOperationFilteredDiningUseCase, exercising success, empty, filtering, edge-case, and repository-failure scenarios.

Changes

Cohort / File(s) Summary
Test Double
domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt
New in-memory FakeDiningRepository with fakeDinings state, shouldThrow flag, setters, and override suspend fun getDining(date: String): List<Dining> which returns data or throws RuntimeException("Network error").
Dining Use Case Tests
domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetDiningUseCaseTest.kt, domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetNotOperationFilteredDiningUseCaseTest.kt
New coroutine-based unit tests that instantiate FakeDiningRepository and verify: normal returns, handling of "미운영" entries, filtering of non-operating/empty-menu items, empty inputs, edge cases, and repository failure behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 I hopped in code with pads so light,

I built a fake repo overnight,
Tests now dance through pass and fail,
Menus, empties, edge-case trail —
Hooray for tests that make builds bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding unit tests for DiningRepository-related UseCases (FakeDiningRepository, GetDiningUseCaseTest, and GetNotOperationFilteredDiningUseCaseTest).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/#1288-add-dining-usecase-test

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt (1)

17-19: Make the fake date-aware to prevent false-positive tests.

getDining(date) currently ignores date, so tests won’t catch wrong date propagation from the use case. Consider storing the requested date (or data by date) and asserting it in tests.

♻️ Minimal refactor example
 class FakeDiningRepository : DiningRepository {
     private var fakeDinings: List<Dining> = emptyList()
     private var shouldThrow: Boolean = false
+    var lastRequestedDate: String? = null
+        private set
@@
     override suspend fun getDining(date: String): List<Dining> {
+        lastRequestedDate = date
         if (shouldThrow) throw RuntimeException("Network error")
         return fakeDinings
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt`
around lines 17 - 19, FakeDiningRepository's getDining(date: String) ignores the
date causing false-positive tests; update the FakeDiningRepository to be
date-aware by either (a) storing a Map<String, List<Dining>> (e.g.,
fakeDiningsByDate) provided in the constructor and returning
fakeDiningsByDate[date] ?: emptyList(), or (b) record the lastRequestedDate
property when getDining(date) is called and return data filtered by that date;
keep the existing shouldThrow behavior (throw RuntimeException when shouldThrow
is true) and expose the map or lastRequestedDate so tests can assert the
requested date and returned data.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetNotOperationFilteredDiningUseCaseTest.kt`:
- Around line 108-117: The test "미운영이 첫 번째 항목이 아닌 경우 제외되지 않는다" contradicts the
filtering rule that any menu containing "미운영" should be excluded; update the
test in GetNotOperationFilteredDiningUseCaseTest.kt to reflect that a dining
whose menu list contains "미운영" (even when not first) is filtered out by
GetNotOperationFilteredDiningUseCase: keep using makeDining(listOf("김치찌개",
"미운영")) and diningRepository.setFakeDinings(...), call
GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01"), then
assert the call is successful and that result.getOrThrow().size equals 0 (or
otherwise assert the dining was excluded) and optionally rename the test to
indicate exclusion when "미운영" appears anywhere in the menu.

---

Nitpick comments:
In
`@domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt`:
- Around line 17-19: FakeDiningRepository's getDining(date: String) ignores the
date causing false-positive tests; update the FakeDiningRepository to be
date-aware by either (a) storing a Map<String, List<Dining>> (e.g.,
fakeDiningsByDate) provided in the constructor and returning
fakeDiningsByDate[date] ?: emptyList(), or (b) record the lastRequestedDate
property when getDining(date) is called and return data filtered by that date;
keep the existing shouldThrow behavior (throw RuntimeException when shouldThrow
is true) and expose the map or lastRequestedDate so tests can assert the
requested date and returned data.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 547edb8 and 11a7a8d.

📒 Files selected for processing (3)
  • domain/src/test/java/in/koreatech/koin/domain/repository/FakeDiningRepository.kt
  • domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetDiningUseCaseTest.kt
  • domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetNotOperationFilteredDiningUseCaseTest.kt

Comment on lines +108 to +117
fun `미운영이 첫 번째 항목이 아닌 경우 제외되지 않는다`() = runTest {
// "미운영"이 첫 번째 항목이 아니면 필터링 대상이 아님
val dining = makeDining(listOf("김치찌개", "미운영"))
diningRepository.setFakeDinings(listOf(dining))

val result = GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01")

assertTrue(result.isSuccess)
assertEquals(1, result.getOrThrow().size)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Test expectation conflicts with non-operational filtering rule.

This case currently expects a dining containing "미운영" (in a non-first menu position) to remain included. If "미운영" marks non-operational meals, it should be excluded regardless of position.

🛠️ Suggested test expectation fix
-    fun `미운영이 첫 번째 항목이 아닌 경우 제외되지 않는다`() = runTest {
-        // "미운영"이 첫 번째 항목이 아니면 필터링 대상이 아님
+    fun `메뉴에 미운영이 포함된 식단은 위치와 무관하게 제외된다`() = runTest {
         val dining = makeDining(listOf("김치찌개", "미운영"))
         diningRepository.setFakeDinings(listOf(dining))

         val result = GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01")

         assertTrue(result.isSuccess)
-        assertEquals(1, result.getOrThrow().size)
+        assertTrue(result.getOrThrow().isEmpty())
     }

Based on learnings: Filter non-operational dining halls by excluding menus containing "미운영" in the dining module.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fun `미운영이 첫 번째 항목이 아닌 경우 제외되지 않는다`() = runTest {
// "미운영"이 첫 번째 항목이 아니면 필터링 대상이 아님
val dining = makeDining(listOf("김치찌개", "미운영"))
diningRepository.setFakeDinings(listOf(dining))
val result = GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01")
assertTrue(result.isSuccess)
assertEquals(1, result.getOrThrow().size)
}
fun `메뉴에 미운영이 포함된 식단은 위치와 무관하게 제외된다`() = runTest {
val dining = makeDining(listOf("김치찌개", "미운영"))
diningRepository.setFakeDinings(listOf(dining))
val result = GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01")
assertTrue(result.isSuccess)
assertTrue(result.getOrThrow().isEmpty())
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@domain/src/test/java/in/koreatech/koin/domain/usecase/dining/GetNotOperationFilteredDiningUseCaseTest.kt`
around lines 108 - 117, The test "미운영이 첫 번째 항목이 아닌 경우 제외되지 않는다" contradicts the
filtering rule that any menu containing "미운영" should be excluded; update the
test in GetNotOperationFilteredDiningUseCaseTest.kt to reflect that a dining
whose menu list contains "미운영" (even when not first) is filtered out by
GetNotOperationFilteredDiningUseCase: keep using makeDining(listOf("김치찌개",
"미운영")) and diningRepository.setFakeDinings(...), call
GetNotOperationFilteredDiningUseCase(diningRepository)("2024-01-01"), then
assert the call is successful and that result.getOrThrow().size equals 0 (or
otherwise assert the dining was excluded) and optionally rename the test to
indicate exclusion when "미운영" appears anywhere in the menu.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@KYM-P KYM-P left a comment

Choose a reason for hiding this comment

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

GOOD

@kongwoojin kongwoojin closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants