-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ #99 from boostcampwm-2022/test/domain
domain layer ํ ์คํธ ์ฝ๋ ์์๋ก ์์ฑ
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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
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
90 changes: 90 additions & 0 deletions
90
domain/src/test/java/com/whyranoid/domain/useCase/GetGroupInfoUseCaseTest.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,90 @@ | ||
package com.whyranoid.domain.useCase | ||
|
||
import com.whyranoid.domain.model.GroupInfo | ||
import com.whyranoid.domain.model.User | ||
import com.whyranoid.domain.repository.GroupRepository | ||
import com.whyranoid.domain.usecase.GetGroupInfoUseCase | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.mock | ||
|
||
class GetGroupInfoUseCaseTest { | ||
|
||
@Before | ||
fun setUp() { | ||
|
||
mockedGroupRepository = mock(GroupRepository::class.java) | ||
|
||
`when`( | ||
mockedGroupRepository.getGroupInfoFlow( | ||
uid = FAKE, | ||
groupId = IS_SUCCESS | ||
) | ||
).thenReturn(flow { emit(MOCKED_GROUP_INFO) }) | ||
|
||
`when`( | ||
mockedGroupRepository.getGroupInfoFlow( | ||
uid = FAKE, | ||
groupId = IS_FAILURE | ||
) | ||
).thenReturn(flow { }) | ||
} | ||
|
||
// uid๋ ์๊ด์์ด groupId๊ฐ "fake" ์ผ ๋ Leader์ name์ด hyunsoo์ธ ๊ทธ๋ฃน์ flow๋ก ๋ฐํ | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@Test | ||
fun getGroupInfoUseCase_groupIdIsFake_returnGroupInfo() = runTest { | ||
// given | ||
val getGroupInfoUseCase = | ||
GetGroupInfoUseCase(mockedGroupRepository).invoke(uid = FAKE, groupId = IS_SUCCESS) | ||
|
||
// when | ||
val groupInfo = getGroupInfoUseCase.firstOrNull() | ||
|
||
// then | ||
assertEquals(IS_SUCCESS, (requireNotNull(groupInfo).leader.name)) | ||
} | ||
|
||
// uid๋ ์๊ด์์ด groupId๊ฐ "fake" ๊ฐ ์๋ ๋ ๊ทธ๋ฃน์ ๋ฐํํ์ง ์์ | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@Test | ||
fun getGroupInfoUseCase_groupIdIsNotFake_returnNothing() = runTest { | ||
// given | ||
val getGroupInfoUseCase = | ||
GetGroupInfoUseCase(mockedGroupRepository).invoke(uid = FAKE, groupId = IS_FAILURE) | ||
|
||
// when | ||
val groupInfo = getGroupInfoUseCase.firstOrNull() | ||
|
||
// then | ||
assertNull(groupInfo) | ||
} | ||
|
||
companion object { | ||
|
||
private lateinit var mockedGroupRepository: GroupRepository | ||
private const val FAKE = "fake" | ||
private const val IS_SUCCESS = "isSuccess" | ||
private const val IS_FAILURE = "isFailure" | ||
|
||
val MOCKED_GROUP_INFO = GroupInfo( | ||
name = FAKE, | ||
groupId = FAKE, | ||
introduce = FAKE, | ||
rules = emptyList(), | ||
headCount = 0, | ||
leader = User( | ||
uid = FAKE, | ||
name = IS_SUCCESS, | ||
profileUrl = FAKE | ||
) | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
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 @@ | ||
mock-maker-inline |