Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Jan 13, 2024
1 parent 70f9238 commit 349dabb
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.twisterrob.travel.domain.london.status

import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.RefreshResult
import net.twisterrob.travel.domain.london.status.api.RefreshUseCase

class DomainRefreshUseCase(
private val historyRepository: HistoryRepository,
private val statusHistoryRepository: StatusHistoryRepository,
) : RefreshUseCase {

override fun refreshLatest(feed: Feed): RefreshResult {
val current = historyRepository.getCurrent(feed)
val latest = historyRepository.getLatest(feed)
val current = statusHistoryRepository.getCurrent(feed)
val latest = statusHistoryRepository.getLatest(feed)

return when {
latest == null -> {
historyRepository.save(current)
statusHistoryRepository.save(current)
RefreshResult.Created(current)
}

Expand All @@ -27,7 +27,7 @@ class DomainRefreshUseCase(
}

else -> {
historyRepository.save(current)
statusHistoryRepository.save(current)
RefreshResult.Refreshed(current, latest)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package net.twisterrob.travel.domain.london.status

import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.ParsedStatusItem
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource

class DomainHistoryRepository(
class DomainStatusHistoryRepository(
private val statusHistoryDataSource: StatusHistoryDataSource,
private val statusDataSource: StatusDataSource,
private val feedParser: FeedParser,
) : HistoryRepository {
) : StatusHistoryRepository {

override fun history(feed: Feed, max: Int, includeCurrent: Boolean): List<ParsedStatusItem> {
val result = mutableListOf<StatusItem>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.twisterrob.travel.domain.london.status.api
import net.twisterrob.travel.domain.london.status.Feed
import net.twisterrob.travel.domain.london.status.StatusItem

interface HistoryRepository {
interface StatusHistoryRepository {

/**
* Returns the top [max] items from the history of [feed] ordered by [StatusItem.retrievedDate],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.mockative.verify
import io.mockative.verifyNoUnmetExpectations
import io.mockative.verifyNoUnverifiedExpectations
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
import kotlin.test.AfterTest
Expand All @@ -19,7 +19,7 @@ class DomainHistoryRepositoryUnitTest_getCurrent {
private val mockHistory: StatusHistoryDataSource = mock()
private val mockStatus: StatusDataSource = mock()
private val mockParser: FeedParser = mock()
private val subject: HistoryRepository = DomainHistoryRepository(mockHistory, mockStatus, mockParser)
private val subject: StatusHistoryRepository = DomainStatusHistoryRepository(mockHistory, mockStatus, mockParser)
private val feed = Feed.TubeDepartureBoardsLineStatus

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.mockative.verify
import io.mockative.verifyNoUnmetExpectations
import io.mockative.verifyNoUnverifiedExpectations
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
import kotlin.test.AfterTest
Expand All @@ -20,7 +20,7 @@ class DomainHistoryRepositoryUnitTest_getLatest {
private val mockHistory: StatusHistoryDataSource = mock()
private val mockStatus: StatusDataSource = mock()
private val mockParser: FeedParser = mock()
private val subject: HistoryRepository = DomainHistoryRepository(mockHistory, mockStatus, mockParser)
private val subject: StatusHistoryRepository = DomainStatusHistoryRepository(mockHistory, mockStatus, mockParser)
private val feed = Feed.TubeDepartureBoardsLineStatus

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.mockative.verify
import io.mockative.verifyNoUnmetExpectations
import io.mockative.verifyNoUnverifiedExpectations
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.ParsedStatusItem
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
Expand All @@ -21,7 +21,7 @@ class DomainHistoryRepositoryUnitTest_history {
private val mockHistory: StatusHistoryDataSource = mock()
private val mockStatus: StatusDataSource = mock()
private val mockParser: FeedParser = mock()
private val subject: HistoryRepository = DomainHistoryRepository(mockHistory, mockStatus, mockParser)
private val subject: StatusHistoryRepository = DomainStatusHistoryRepository(mockHistory, mockStatus, mockParser)
private val feed = Feed.TubeDepartureBoardsLineStatus

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.mockative.verify
import io.mockative.verifyNoUnmetExpectations
import io.mockative.verifyNoUnverifiedExpectations
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
import kotlin.test.AfterTest
Expand All @@ -16,7 +16,7 @@ class DomainHistoryRepositoryUnitTest_save {
private val mockHistory: StatusHistoryDataSource = mock()
private val mockStatus: StatusDataSource = mock()
private val mockParser: FeedParser = mock()
private val subject: HistoryRepository = DomainHistoryRepository(mockHistory, mockStatus, mockParser)
private val subject: StatusHistoryRepository = DomainStatusHistoryRepository(mockHistory, mockStatus, mockParser)

@AfterTest
fun verify() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.mockative.mock
import io.mockative.verify
import io.mockative.verifyNoUnmetExpectations
import io.mockative.verifyNoUnverifiedExpectations
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.RefreshResult
import net.twisterrob.travel.domain.london.status.api.RefreshUseCase
import kotlin.test.AfterTest
Expand All @@ -15,7 +15,7 @@ import kotlin.test.assertEquals

class DomainRefreshUseCaseUnitTest {

private val mockHistory: HistoryRepository = mock()
private val mockHistory: StatusHistoryRepository = mock()
private val subject: RefreshUseCase = DomainRefreshUseCase(mockHistory)
private val feed = Feed.TubeDepartureBoardsLineStatus

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import io.mockative.Mock
import io.mockative.classOf
import io.mockative.mock
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
import net.twisterrob.travel.domain.london.status.api.StatusDataSource

@Suppress("unused") // Used by mockative KSP.
object Mocks {

@Mock
private val historyRepository = mock(classOf<HistoryRepository>())
private val statusHistoryRepository = mock(classOf<StatusHistoryRepository>())

@Mock
private val statusHistoryDataSource = mock(classOf<StatusHistoryDataSource>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
package io.mockative

import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
import net.twisterrob.travel.domain.london.status.api.StatusDataSource

inline fun <reified T : Any> mock(): T =
when (T::class) {
HistoryRepository::class -> mock(HistoryRepository::class) as T
StatusHistoryRepository::class -> mock(StatusHistoryRepository::class) as T
StatusHistoryDataSource::class -> mock(StatusHistoryDataSource::class) as T
StatusDataSource::class -> mock(StatusDataSource::class) as T
FeedParser::class -> mock(FeedParser::class) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.micronaut.views.View
import net.twisterrob.blt.data.StaticData
import net.twisterrob.blt.io.feeds.trackernet.LineStatusFeed
import net.twisterrob.travel.domain.london.status.Feed
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.ParsedStatusItem
import net.twisterrob.travel.statushistory.viewmodel.LineColor
import net.twisterrob.travel.statushistory.viewmodel.Result
Expand All @@ -22,7 +22,7 @@ import java.util.Date

@Controller
class LineStatusHistoryController(
private val useCase: HistoryRepository,
private val useCase: StatusHistoryRepository,
private val staticData: StaticData,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import net.twisterrob.blt.data.StaticData
import net.twisterrob.blt.io.feeds.LocalhostUrlBuilder
import net.twisterrob.blt.io.feeds.TFLUrlBuilder
import net.twisterrob.blt.io.feeds.URLBuilder
import net.twisterrob.travel.domain.london.status.DomainHistoryRepository
import net.twisterrob.travel.domain.london.status.DomainStatusHistoryRepository
import net.twisterrob.travel.domain.london.status.DomainRefreshUseCase
import net.twisterrob.travel.domain.london.status.api.FeedParser
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import net.twisterrob.travel.domain.london.status.api.RefreshUseCase
import net.twisterrob.travel.domain.london.status.api.StatusDataSource
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource
Expand All @@ -33,22 +33,21 @@ class Dependencies {
* External dependency from domain layer in common KMP code.
*/
@Prototype
fun historyUseCase(
fun historyRepository(
statusHistoryDataSource: StatusHistoryDataSource,
statusDataSource: StatusDataSource,
feedParser: FeedParser,
): HistoryRepository =
DomainHistoryRepository(statusHistoryDataSource, statusDataSource, feedParser)
): StatusHistoryRepository =
DomainStatusHistoryRepository(statusHistoryDataSource, statusDataSource, feedParser)

/**
* External dependency from domain layer in common KMP code.
*/
@Prototype
fun refreshUseCase(
statusHistoryDataSource: StatusHistoryDataSource,
statusDataSource: StatusDataSource,
statusHistoryRepository: StatusHistoryRepository,
): RefreshUseCase =
DomainRefreshUseCase(statusHistoryDataSource, statusDataSource)
DomainRefreshUseCase(statusHistoryRepository)

@Singleton
fun staticData(): StaticData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.micronaut.test.extensions.junit5.annotation.MicronautTest
import jakarta.inject.Inject
import net.twisterrob.blt.data.StaticData
import net.twisterrob.blt.model.LineColors
import net.twisterrob.travel.domain.london.status.api.HistoryRepository
import net.twisterrob.travel.domain.london.status.api.StatusHistoryRepository
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.endsWith
import org.hamcrest.Matchers.startsWith
Expand All @@ -26,8 +26,8 @@ class LineStatusHistoryControllerIntegrationTest {
@Inject
lateinit var client: BlockingHttpClient

@MockBean(HistoryRepository::class)
val historyUseCase: HistoryRepository = mock()
@MockBean(StatusHistoryRepository::class)
val historyUseCase: StatusHistoryRepository = mock()

@MockBean(StaticData::class)
val staticData: StaticData = mock()
Expand Down

0 comments on commit 349dabb

Please sign in to comment.