Skip to content

Commit

Permalink
test: BrowseProblemsUseCase 단위 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hun-ca committed Jul 14, 2024
1 parent 0358450 commit be56d81
Showing 1 changed file with 48 additions and 0 deletions.
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()) }
}
}

0 comments on commit be56d81

Please sign in to comment.