Skip to content

Commit

Permalink
refactor: unit test code
Browse files Browse the repository at this point in the history
  • Loading branch information
hun-ca committed Jul 15, 2024
1 parent 0d9e43e commit 033a431
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class ReadArticleUseCaseTest : BehaviorSpec({
lateinit var useCase: ReadArticleUseCase
val useCaseIn = ReadArticleUseCaseIn(articleId = 1L)

given("아티클 조회 요청이 온 상황에서") {
beforeContainer {
articleDao = mockk<ArticleDao>()
readArticleWriterRecordService = mockk<ReadArticleWriterRecordService>()
browseArticleProblemsService = mockk<BrowseArticleProblemsService>()
useCase = ReadArticleUseCase(articleDao, readArticleWriterRecordService, browseArticleProblemsService)
}
beforeContainer {
articleDao = mockk<ArticleDao>()
readArticleWriterRecordService = mockk<ReadArticleWriterRecordService>()
browseArticleProblemsService = mockk<BrowseArticleProblemsService>()
useCase = ReadArticleUseCase(articleDao, readArticleWriterRecordService, browseArticleProblemsService)
}

given("아티클 조회 요청이 온 상황에서") {
`when`("아티클과 작가가 존재할 경우") {
val record = SelectArticleRecord(
articleId = 1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ class BrowseProblemsUseCaseTest : BehaviorSpec({

lateinit var problemDao: ProblemDao
lateinit var useCase: BrowseProblemsUseCase
lateinit var useCaseIn: BrowseProblemsUseCaseIn
val useCaseIn = BrowseProblemsUseCaseIn(articleId = 1L)

given("특정 아티클에 대한") {
beforeContainer {
problemDao = mockk<ProblemDao>()
useCase = BrowseProblemsUseCase(problemDao)
useCaseIn = BrowseProblemsUseCaseIn(articleId = 1L)
}
beforeContainer {
problemDao = mockk<ProblemDao>()
useCase = BrowseProblemsUseCase(problemDao)
}

given("특정 아티클에 대한") {
`when`("문제가 존재할 경우") {
val problemIdsRecord = ProblemIdsRecord(listOf(1, 2, 3))
every { problemDao.selectProblemsByArticleId(any()) } returns problemIdsRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class CheckProblemUseCaseTest : BehaviorSpec({
lateinit var submitHistoryDao: SubmitHistoryDao
lateinit var useCase: CheckProblemUseCase

given("문제 정답 확인 요청이 온 상황에서") {

beforeContainer {
problemDao = mockk<ProblemDao>()
submitHistoryDao = mockk<SubmitHistoryDao>()
useCase = CheckProblemUseCase(problemDao, submitHistoryDao)
}
beforeContainer {
problemDao = mockk<ProblemDao>()
submitHistoryDao = mockk<SubmitHistoryDao>()
useCase = CheckProblemUseCase(problemDao, submitHistoryDao)
}

given("문제 정답 확인 요청이 온 상황에서") {
`when`("제출 값과 문제 정답이 같을 경우") {
val submissionVal = "1"
val answer = submissionVal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ class ReadProblemUseCaseTest : BehaviorSpec({
lateinit var problemDao: ProblemDao
lateinit var contentsJsonMapper: ContentsJsonMapper
lateinit var useCase: ReadProblemUseCase
lateinit var useCaseIn: ReadProblemUseCaseIn
val useCaseIn = ReadProblemUseCaseIn(problemId = 1L)

given("문제를 조회할 상황에서") {
beforeContainer {
problemDao = mockk<ProblemDao>()
contentsJsonMapper = mockk<ContentsJsonMapper>()
useCase = ReadProblemUseCase(problemDao, contentsJsonMapper)
useCaseIn = ReadProblemUseCaseIn(problemId = 1L)
}
beforeContainer {
problemDao = mockk<ProblemDao>()
contentsJsonMapper = mockk<ContentsJsonMapper>()
useCase = ReadProblemUseCase(problemDao, contentsJsonMapper)
}

given("문제를 조회할 상황에서") {
`when`("문제가 존재할 경우") {
val problemRecord = SelectProblemRecord(id = 1L, title = "title", contents = "{}")
val contents = Contents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ class SubscribeWorkbookUseCaseTest : BehaviorSpec({
lateinit var memberService: MemberService
lateinit var applicationEventPublisher: ApplicationEventPublisher
lateinit var useCase: SubscribeWorkbookUseCase
val workbookId = 1L
val useCaseIn = SubscribeWorkbookUseCaseIn(workbookId = workbookId, email = "[email protected]")

beforeContainer {
subscriptionDao = mockk<SubscriptionDao>()
memberService = mockk<MemberService>()
applicationEventPublisher = mockk<ApplicationEventPublisher>()
useCase = SubscribeWorkbookUseCase(subscriptionDao, memberService, applicationEventPublisher)
}

given("구독 요청이 온 상황에서") {

beforeContainer {
subscriptionDao = mockk<SubscriptionDao>()
memberService = mockk<MemberService>()
applicationEventPublisher = mockk<ApplicationEventPublisher>()
useCase = SubscribeWorkbookUseCase(subscriptionDao, memberService, applicationEventPublisher)
}

`when`("subscriptionStatus가 null일 경우") {
val workbookId = 1L
val useCaseIn = SubscribeWorkbookUseCaseIn(workbookId = workbookId, email = "[email protected]")
val serviceOutDto = MemberIdOutDto(memberId = 1L)
val event = WorkbookSubscriptionEvent(workbookId)

Expand All @@ -57,8 +56,6 @@ class SubscribeWorkbookUseCaseTest : BehaviorSpec({
}

`when`("구독을 취소한 경우") {
val workbookId = 1L
val useCaseIn = SubscribeWorkbookUseCaseIn(workbookId = workbookId, email = "[email protected]")
val day = 2
val lastDay = 3
val serviceOutDto = MemberIdOutDto(memberId = 1L)
Expand Down Expand Up @@ -86,8 +83,6 @@ class SubscribeWorkbookUseCaseTest : BehaviorSpec({
}

`when`("이미 구독하고 있을 경우") {
val workbookId = 1L
val useCaseIn = SubscribeWorkbookUseCaseIn(workbookId = workbookId, email = "[email protected]")
val day = 2
val lastDay = 3
val serviceOutDto = MemberIdOutDto(memberId = 1L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ReadWorkbookUseCaseTest : BehaviorSpec({
lateinit var useCase: ReadWorkbookUseCase
val useCaseIn = ReadWorkbookUseCaseIn(workbookId = 1L)

given("워크북 조회 요청이 온 상황에서") {
beforeContainer {
workbookDao = mockk<WorkbookDao>()
workbookArticleService = mockk<WorkbookArticleService>()
workbookMemberService = mockk<WorkbookMemberService>()
useCase = ReadWorkbookUseCase(workbookDao, workbookArticleService, workbookMemberService)
}
beforeContainer {
workbookDao = mockk<WorkbookDao>()
workbookArticleService = mockk<WorkbookArticleService>()
workbookMemberService = mockk<WorkbookMemberService>()
useCase = ReadWorkbookUseCase(workbookDao, workbookArticleService, workbookMemberService)
}

given("워크북 조회 요청이 온 상황에서") {
`when`("워크북과 작가가 존재할 경우") {
every { workbookDao.selectWorkBook(any()) } returns SelectWorkBookRecord(
id = 1L,
Expand Down

0 comments on commit 033a431

Please sign in to comment.