Skip to content

Commit

Permalink
[chore] ktFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Feb 9, 2024
1 parent ae1b0c8 commit 7164bb8
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.moya.funch.datasource.local

import com.moya.funch.datastore.UserDataStore
import com.moya.funch.model.ProfileModel
import timber.log.Timber
import javax.inject.Inject
import timber.log.Timber

class LocalUserDataSourceImpl @Inject constructor(
private val userDataStore: UserDataStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.moya.funch.entity.SubwayLine
import com.moya.funch.entity.SubwayStation
import com.moya.funch.entity.profile.Profile
import com.moya.funch.network.dto.request.MemberRequest
import com.moya.funch.network.dto.response.match.SubwayResponse
import com.moya.funch.network.dto.response.member.MemberResponse

data class ProfileModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ internal class LocalUserDataSourceImplTest {
// when
val actualResult: Result<ProfileModel> = localUserDataSource.fetchUserProfile()
// then
assertAll({ coVerify(exactly = 1) { userDataStore.hasUserId() } },
assertAll(
{ coVerify(exactly = 1) { userDataStore.hasUserId() } },
{ coVerify(exactly = 1) { userDataStore.userCode } },
{ coVerify(exactly = 1) { userDataStore.mbti } },
{ assertThat(actualResult.isSuccess).isTrue() },
{ assertThat(actualResult.getOrNull()).isEqualTo(expectedProfile) })
{ assertThat(actualResult.getOrNull()).isEqualTo(expectedProfile) }
)
}

@Test
Expand All @@ -73,9 +75,10 @@ internal class LocalUserDataSourceImplTest {
// when
val actualResult: Result<ProfileModel> = localUserDataSource.fetchUserProfile()
// then
assertAll({ coVerify(exactly = 1) { userDataStore.hasUserId() } },
{ assertThat(actualResult.isFailure).isTrue() })

assertAll(
{ coVerify(exactly = 1) { userDataStore.hasUserId() } },
{ assertThat(actualResult.isFailure).isTrue() }
)
}

@Test
Expand All @@ -95,10 +98,12 @@ internal class LocalUserDataSourceImplTest {
// when
val actualResult: Result<Unit> = localUserDataSource.saveUserProfile(profile)
// then
assertAll({ coVerify(exactly = 1) { userDataStore.clear() } },
assertAll(
{ coVerify(exactly = 1) { userDataStore.clear() } },
{ coVerify(exactly = 1) { userDataStore.userCode = profile.userCode } },
{ coVerify(exactly = 1) { userDataStore.mbti = profile.mbti } },
{ assertThat(actualResult.isSuccess).isTrue() })
{ assertThat(actualResult.isSuccess).isTrue() }
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ internal class RemoteUserDataSourceImplTest {

@Test
fun `id가 있으면 id로 profile을 불러온다`() = runTest {
//given
// given
coEvery { userDataStore.hasUserId() } returns true
//when
// when
remoteUserDataSource.fetchUserProfile()
//then
// then
assertAll(
{ coVerify(exactly = 1) { memberService.findMemberById(any()) } },
{ coVerify(exactly = 0) { memberService.findMemberByDeviceNumber(any()) } }
Expand All @@ -49,11 +49,11 @@ internal class RemoteUserDataSourceImplTest {

@Test
fun `id가 없으면 device id로 profile을 불러온다`() = runTest {
//given
// given
coEvery { userDataStore.hasUserId() } returns false
//when
// when
remoteUserDataSource.fetchUserProfile()
//then
// then
assertAll(
{ coVerify(exactly = 0) { memberService.findMemberById(any()) } },
{ coVerify(exactly = 1) { memberService.findMemberByDeviceNumber(any()) } }
Expand All @@ -66,4 +66,3 @@ internal class RemoteUserDataSourceImplTest {
val coroutineExtension = CoroutinesTestExtension()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class MemberRepositoryImplTest {

@Test
fun `local에 User Profile이 있으면 불러온다`() = runTest {
//given
// given
coEvery { localUserDataSource.fetchUserProfile() } returns Result.success(
ProfileModel(
userCode = "NONE",
Expand All @@ -57,9 +57,9 @@ internal class MemberRepositoryImplTest {
mbti = "INTJ"
)
)
//when
// when
val result = memberRepository.fetchUserProfile()
//then
// then
assertAll(
{ coVerify(exactly = 1) { localUserDataSource.fetchUserProfile() } },
{ coVerify(exactly = 0) { remoteUserDataSource.fetchUserProfile() } },
Expand All @@ -70,7 +70,7 @@ internal class MemberRepositoryImplTest {

@Test
fun `local에 User Profile이 없으면 remote에서 불러온다`() = runTest {
//given
// given
coEvery { localUserDataSource.fetchUserProfile() } returns Result.failure(
Exception("User Profile not found")
)
Expand All @@ -90,9 +90,9 @@ internal class MemberRepositoryImplTest {
coEvery { localUserDataSource.saveUserProfile(any()) } returns Result.success(
Unit
)
//when
// when
val result = memberRepository.fetchUserProfile()
//then
// then
assertAll(
{ coVerify(exactly = 1) { localUserDataSource.fetchUserProfile() } },
{ coVerify(exactly = 1) { remoteUserDataSource.fetchUserProfile() } },
Expand All @@ -103,7 +103,7 @@ internal class MemberRepositoryImplTest {

@Test
fun `User Profile을 만들고 local에 저장한다`() = runTest {
//given
// given
val profile = Profile()
coEvery { remoteUserDataSource.createUserProfile(any()) } returns Result.success(
ProfileModel(
Expand All @@ -118,9 +118,9 @@ internal class MemberRepositoryImplTest {
mbti = "INTJ"
)
)
//when
// when
val profileResult = memberRepository.createUserProfile(profile)
//then
// then
assertAll(
{ coVerify(exactly = 1) { remoteUserDataSource.createUserProfile(any()) } },
{ coVerify(exactly = 1) { localUserDataSource.saveUserProfile(any()) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ import javax.inject.Inject
class CreateUserProfileUseCaseImpl @Inject constructor(
private val memberRepository: MemberRepository
) : CreateUserProfileUseCase {
override suspend operator fun invoke(
profile: Profile
): Result<Profile> {
override suspend operator fun invoke(profile: Profile): Result<Profile> {
return memberRepository.createUserProfile(profile)
}
}

fun interface CreateUserProfileUseCase {
suspend operator fun invoke(
profile: Profile
): Result<Profile>
suspend operator fun invoke(profile: Profile): Result<Profile>
}


Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ fun interface LoadUserProfileUseCase {

suspend operator fun invoke(): Result<Profile>
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ProfileTest {

@Test
fun `code는 모두 숫자 혹은 대문자 알파벳이다`() {

assertThrows<IllegalArgumentException>("Code must be all numbers or upper case alphabets") {
Profile(code = "a123")
}
Expand Down Expand Up @@ -37,7 +36,7 @@ class ProfileTest {
assertThrows<IllegalArgumentException>("Code must not be blank") {
Profile(code = "123")
}
},
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.moya.funch.network.dto.response.match.ProfileResponse
import com.moya.funch.network.dto.response.match.RecommendResponse
import com.moya.funch.rule.CoroutinesTestExtension
import io.mockk.junit5.MockKExtension
import java.io.File
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
Expand All @@ -22,7 +23,6 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.RegisterExtension
import retrofit2.Retrofit
import retrofit2.create
import java.io.File

@OptIn(ExperimentalCoroutinesApi::class)
@ExtendWith(MockKExtension::class)
Expand Down

0 comments on commit 7164bb8

Please sign in to comment.