-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fab3da5
commit 70f9238
Showing
10 changed files
with
242 additions
and
50 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
22 changes: 22 additions & 0 deletions
22
...src/commonMain/kotlin/net/twisterrob/travel/domain/london/status/api/HistoryRepository.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 |
---|---|---|
@@ -1,12 +1,34 @@ | ||
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 { | ||
|
||
/** | ||
* Returns the top [max] items from the history of [feed] ordered by [StatusItem.retrievedDate], | ||
* including the current status if [includeCurrent] is true. | ||
* | ||
* @param max maximum number of items to return, current is not included in the count. | ||
* @param includeCurrent whether to include the current status in the result. | ||
*/ | ||
fun history(feed: Feed, max: Int, includeCurrent: Boolean): List<ParsedStatusItem> | ||
|
||
/** | ||
* @return the current live status. | ||
*/ | ||
fun getCurrent(feed: Feed): StatusItem | ||
|
||
/** | ||
* @return the latest item from history, or null if there is no history. | ||
*/ | ||
fun getLatest(feed: Feed): StatusItem? | ||
|
||
/** | ||
* Saves the item to history. | ||
* If [StatusItem.retrievedDate] is later than the latest item in history, this item will become the latest. | ||
* | ||
* @param item the item to save. | ||
*/ | ||
fun save(item: StatusItem) | ||
} |
52 changes: 52 additions & 0 deletions
52
.../net/twisterrob/travel/domain/london/status/DomainHistoryRepositoryUnitTest_getCurrent.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,52 @@ | ||
package net.twisterrob.travel.domain.london.status | ||
|
||
import io.mockative.any | ||
import io.mockative.every | ||
import io.mockative.mock | ||
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.StatusDataSource | ||
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource | ||
import kotlin.test.AfterTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertSame | ||
|
||
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 feed = Feed.TubeDepartureBoardsLineStatus | ||
|
||
@AfterTest | ||
fun verify() { | ||
listOf(mockHistory, mockStatus, mockParser).forEach { | ||
verifyNoUnverifiedExpectations(it) | ||
verifyNoUnmetExpectations(it) | ||
} | ||
} | ||
|
||
@Test fun `returns successful item`() { | ||
val current = SuccessfulStatusItem() | ||
every { mockStatus.getCurrent(any()) }.returns(current) | ||
|
||
val result = subject.getCurrent(feed) | ||
assertSame(current, result) | ||
|
||
verify { mockStatus.getCurrent(feed) }.wasInvoked() | ||
} | ||
|
||
@Test fun `returns failed item`() { | ||
val current = FailedStatusItem() | ||
every { mockStatus.getCurrent(any()) }.returns(current) | ||
|
||
val result = subject.getCurrent(feed) | ||
assertSame(current, result) | ||
|
||
verify { mockStatus.getCurrent(feed) }.wasInvoked() | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...n/net/twisterrob/travel/domain/london/status/DomainHistoryRepositoryUnitTest_getLatest.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,62 @@ | ||
package net.twisterrob.travel.domain.london.status | ||
|
||
import io.mockative.any | ||
import io.mockative.every | ||
import io.mockative.mock | ||
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.StatusDataSource | ||
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource | ||
import kotlin.test.AfterTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertSame | ||
|
||
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 feed = Feed.TubeDepartureBoardsLineStatus | ||
|
||
@AfterTest | ||
fun verify() { | ||
listOf(mockHistory, mockStatus, mockParser).forEach { | ||
verifyNoUnverifiedExpectations(it) | ||
verifyNoUnmetExpectations(it) | ||
} | ||
} | ||
|
||
@Test fun `returns successful item`() { | ||
val latest = SuccessfulStatusItem() | ||
every { mockHistory.getAll(any(), any()) }.returns(listOf(latest)) | ||
|
||
val result = subject.getLatest(feed) | ||
assertSame(latest, result) | ||
|
||
verify { mockHistory.getAll(feed, 1) }.wasInvoked() | ||
} | ||
|
||
@Test fun `returns failed item`() { | ||
val latest = FailedStatusItem() | ||
every { mockHistory.getAll(any(), any()) }.returns(listOf(latest)) | ||
|
||
val result = subject.getLatest(feed) | ||
assertSame(latest, result) | ||
|
||
verify { mockHistory.getAll(feed, 1) }.wasInvoked() | ||
} | ||
|
||
@Test fun `returns no item`() { | ||
every { mockHistory.getAll(any(), any()) }.returns(emptyList()) | ||
|
||
val result = subject.getLatest(feed) | ||
assertNull(result) | ||
|
||
verify { mockHistory.getAll(feed, 1) }.wasInvoked() | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...kotlin/net/twisterrob/travel/domain/london/status/DomainHistoryRepositoryUnitTest_save.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,44 @@ | ||
package net.twisterrob.travel.domain.london.status | ||
|
||
import io.mockative.mock | ||
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.StatusDataSource | ||
import net.twisterrob.travel.domain.london.status.api.StatusHistoryDataSource | ||
import kotlin.test.AfterTest | ||
import kotlin.test.Test | ||
|
||
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) | ||
|
||
@AfterTest | ||
fun verify() { | ||
listOf(mockHistory, mockStatus, mockParser).forEach { | ||
verifyNoUnverifiedExpectations(it) | ||
verifyNoUnmetExpectations(it) | ||
} | ||
} | ||
|
||
@Test fun `returns successful item`() { | ||
val current = SuccessfulStatusItem() | ||
|
||
subject.save(current) | ||
|
||
verify { mockHistory.add(current) }.wasInvoked() | ||
} | ||
|
||
@Test fun `returns failed item`() { | ||
val current = FailedStatusItem() | ||
|
||
subject.save(current) | ||
|
||
verify { mockHistory.add(current) }.wasInvoked() | ||
} | ||
} |
Oops, something went wrong.