Skip to content

Commit

Permalink
[#21] Refactor single val class
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Dec 26, 2022
1 parent 88d5caa commit 16ffe7c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.nimblehq.blisskmmic.data.repository

import co.nimblehq.blisskmmic.domain.model.DateComponent
import co.nimblehq.blisskmmic.domain.repository.DeviceInfoRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
Expand All @@ -10,11 +9,8 @@ class DeviceInfoRepositoryImpl(
private val clock: Clock
): DeviceInfoRepository {

override fun getCurrentDate(): Flow<DateComponent> {
val now = clock.now()
val dateHeader = DateComponent(
now.epochSeconds
)
return flowOf(dateHeader)
override fun getCurrentDate(): Flow<Long> {
val now = clock.now().epochSeconds
return flowOf(now)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package co.nimblehq.blisskmmic.domain.repository

import co.nimblehq.blisskmmic.domain.model.DateComponent
import kotlinx.coroutines.flow.Flow

interface DeviceInfoRepository {

fun getCurrentDate(): Flow<DateComponent>
fun getCurrentDate(): Flow<Long>
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package co.nimblehq.blisskmmic.domain.usecase

import co.nimblehq.blisskmmic.domain.model.DateComponent
import co.nimblehq.blisskmmic.domain.repository.DeviceInfoRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.Month

interface GetCurrentDateUseCase {

operator fun invoke(): Flow<DateComponent>
operator fun invoke(): Flow<Long>
}

class GetCurrentDateUseCaseImpl(
private val deviceInfoRepository: DeviceInfoRepository
) : GetCurrentDateUseCase {

override operator fun invoke(): Flow<DateComponent> {
return deviceInfoRepository
.getCurrentDate()
override operator fun invoke(): Flow<Long> {
return deviceInfoRepository.getCurrentDate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GetProfileUseCaseImpl(
) : GetProfileUseCase {

override operator fun invoke(): Flow<User> {
return userRepository
.getProfile()
return userRepository.getProfile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private const val TIME: Long = 100_000
@UsesMocks(Clock::class)
@ExperimentalCoroutinesApi
class DeviceInfoRepositoryTest {

private val mocker = Mocker()
private val clock = MockClock(mocker)
private val instant = Instant.fromEpochSeconds(TIME)
Expand All @@ -34,7 +34,7 @@ class DeviceInfoRepositoryTest {
deviceInfoRepository
.getCurrentDate()
.test {
awaitItem().timeInterval shouldBe TIME
awaitItem() shouldBe TIME
awaitComplete()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package co.nimblehq.blisskmmic.domain.usecase

import app.cash.turbine.test
import co.nimblehq.blisskmmic.domain.model.DateComponent
import co.nimblehq.blisskmmic.domain.model.fakeDateComponent
import co.nimblehq.blisskmmic.domain.repository.DeviceInfoRepository
import co.nimblehq.blisskmmic.domain.repository.MockDeviceInfoRepository
import io.kotest.matchers.shouldBe
Expand All @@ -11,19 +9,18 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.kodein.mock.Mocker
import org.kodein.mock.UsesFakes
import org.kodein.mock.UsesMocks
import kotlin.test.BeforeTest
import kotlin.test.Test

private const val TIME = 100L

@UsesMocks(DeviceInfoRepository::class)
@UsesFakes(DateComponent::class)
@ExperimentalCoroutinesApi
class GetCurrentDateUseCaseTest {

private val mocker = Mocker()
private val deviceInfoRepository = MockDeviceInfoRepository(mocker)
private val dateComponent = fakeDateComponent()
private val getCurrentDateUseCase = GetCurrentDateUseCaseImpl(deviceInfoRepository)

@BeforeTest
Expand All @@ -35,11 +32,11 @@ class GetCurrentDateUseCaseTest {
fun `When calling getCurrent with a success response- it returns correct object`() = runTest {
mocker.every {
deviceInfoRepository.getCurrentDate()
} returns flowOf(dateComponent)
} returns flowOf(TIME)

getCurrentDateUseCase()
.test {
awaitItem().timeInterval shouldBe dateComponent.timeInterval
awaitItem() shouldBe TIME
awaitComplete()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package co.nimblehq.blisskmmic.domain.platform.datetime
import io.kotest.matchers.shouldBe
import kotlin.test.Test

private const val PAST_TIME_SINCE: Long = 1_000_000
private const val TIME_SINCE: Long = 1_000_000_000
private const val PAST_TIME_SINCE = 1_000_000L
private const val TIME_SINCE = 1_000_000_000L

class DateTimeFormatterTest {

Expand Down

0 comments on commit 16ffe7c

Please sign in to comment.