-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: BrowseProblemsUseCase 단위 테스트 추가
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
api/src/test/kotlin/com/few/api/domain/problem/usecase/BrowseProblemsUseCaseTest.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,48 @@ | ||
package com.few.api.domain.problem.usecase | ||
|
||
import com.few.api.domain.problem.usecase.dto.BrowseProblemsUseCaseIn | ||
import com.few.api.repo.dao.problem.ProblemDao | ||
import com.few.api.repo.dao.problem.record.ProblemIdsRecord | ||
import io.mockk.every | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class BrowseProblemsUseCaseTest { | ||
|
||
val problemDao: ProblemDao = mockk<ProblemDao>() | ||
|
||
val useCase = BrowseProblemsUseCase(problemDao) | ||
|
||
@Test | ||
fun `특정 아티클에 문제가 존재할 경우 문제번호가 정상적으로 조회된다`() { | ||
// given | ||
val useCaseIn = BrowseProblemsUseCaseIn(articleId = 1L) | ||
val problemIdsRecord = ProblemIdsRecord(listOf(1, 2, 3)) | ||
|
||
every { problemDao.selectProblemsByArticleId(any()) } returns problemIdsRecord | ||
|
||
// when | ||
useCase.execute(useCaseIn) | ||
|
||
// then | ||
verify(exactly = 1) { problemDao.selectProblemsByArticleId(any()) } | ||
} | ||
|
||
@Test | ||
fun `특정 아티클에 문제가 존재하지 않을 경우 예외가 발생한다`() { | ||
// given | ||
val useCaseIn = BrowseProblemsUseCaseIn(articleId = 1L) | ||
|
||
every { problemDao.selectProblemsByArticleId(any()) } returns null | ||
|
||
// when / then | ||
Assertions.assertThrows(Exception::class.java) { useCase.execute(useCaseIn) } | ||
verify(exactly = 1) { problemDao.selectProblemsByArticleId(any()) } | ||
} | ||
} |