Issue#13 First part of the Robolectric Documentation

This commit is contained in:
Gergely Hegedus 2022-01-26 20:28:43 +02:00
parent 65f42bcbff
commit 163bb8cd10
6 changed files with 314 additions and 11 deletions

View file

@ -0,0 +1,51 @@
package org.fnives.test.showcase.storage.favourite
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.jupiter.api.Disabled
@Disabled("CodeKata")
@OptIn(ExperimentalCoroutinesApi::class)
class CodeKataFavouriteContentLocalStorage {
@Before
fun setUp() {
}
@After
fun tearDown() {
}
/** GIVEN just created database WHEN querying THEN empty list is returned */
@Test
fun atTheStartOurDatabaseIsEmpty() = runBlocking {
}
/** GIVEN content_id WHEN added to Favourite THEN it can be read out */
@Test
fun addingContentIdToFavouriteCanBeLaterReadOut() {
}
/** GIVEN content_id added WHEN removed to Favourite THEN it no longer can be read out */
@Test
fun contentIdAddedThenRemovedCanNoLongerBeReadOut() {
}
/** GIVEN empty database WHILE observing content WHEN favourite added THEN change is emitted */
@Test
fun addingFavouriteUpdatesExistingObservers() {
}
/** GIVEN non empty database WHILE observing content WHEN favourite removed THEN change is emitted */
@Test
fun removingFavouriteUpdatesExistingObservers() {
}
/** GIVEN an observed WHEN adding and removing from it THEN we only get the expected amount of updates */
@Test
fun noUnexpectedUpdates() {
}
}

View file

@ -1,4 +1,4 @@
package org.fnives.test.showcase.favourite
package org.fnives.test.showcase.storage.favourite
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -42,6 +42,14 @@ internal class FavouriteContentLocalStorageImplTest : KoinTest {
stopKoin()
}
/** GIVEN just created database WHEN querying THEN empty list is returned */
@Test
fun atTheStartOurDatabaseIsEmpty() = runTest(testDispatcher) {
val actual = sut.observeFavourites().first()
Assert.assertEquals(emptyList<ContentId>(), actual)
}
/** GIVEN content_id WHEN added to Favourite THEN it can be read out */
@Test
fun addingContentIdToFavouriteCanBeLaterReadOut() = runTest(testDispatcher) {
@ -69,7 +77,6 @@ internal class FavouriteContentLocalStorageImplTest : KoinTest {
@Test
fun addingFavouriteUpdatesExistingObservers() = runTest(testDispatcher) {
val expected = listOf(listOf(), listOf(ContentId("a")))
val actual = async(coroutineContext) { sut.observeFavourites().take(2).toList() }
advanceUntilIdle()
@ -95,4 +102,19 @@ internal class FavouriteContentLocalStorageImplTest : KoinTest {
Assert.assertEquals(expected, actual.getCompleted())
}
/** GIVEN an observed WHEN adding and removing from it THEN we only get the expected amount of updates */
@Test
fun noUnexpectedUpdates() = runTest(testDispatcher) {
val actual = async(coroutineContext) { sut.observeFavourites().take(4).toList() }
advanceUntilIdle()
sut.markAsFavourite(ContentId("a"))
advanceUntilIdle()
sut.deleteAsFavourite(ContentId("a"))
advanceUntilIdle()
Assert.assertFalse(actual.isCompleted)
actual.cancel()
}
}