diff --git a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/SponsorDummyDatas.kt b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/SponsorDummyDatas.kt index a2f318b8e..dc9154d73 100644 --- a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/SponsorDummyDatas.kt +++ b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/SponsorDummyDatas.kt @@ -1,45 +1,51 @@ package io.github.droidkaigi.confsched2019 -import com.soywiz.klock.DateTime -import com.soywiz.klock.hours -import io.github.droidkaigi.confsched2019.model.SponsorCategory import io.github.droidkaigi.confsched2019.model.Sponsor +import io.github.droidkaigi.confsched2019.model.SponsorCategory -private val startTime = - DateTime.createAdjusted(2019, 2, 7, 10, 0).toOffsetUnadjusted(9.hours).utc - -fun dummySponsorsData(): List { +fun dummySponsorCategoriesData(): List { return listOf( SponsorCategory( - SponsorCategory.Category.PLATINUM, - 1, - listOf( + category = SponsorCategory.Category.PLATINUM, + index = 1, + sponsors = listOf( + Sponsor( + name = "mercari", + url = "https://tech.mercari.com/", + image = "https://droidkaigi.jp/2019/images/sponsors/25_mercari.png" + ) + ) + ), + SponsorCategory( + category = SponsorCategory.Category.GOLD, + index = 2, + sponsors = listOf( Sponsor( - "name1", - "url1", - "image1" + name = "google developers", + url = "https://developers.google.com/", + image = "https://droidkaigi.jp/2019/images/sponsors/aa_google.png" ) ) ), SponsorCategory( - SponsorCategory.Category.GOLD, - 2, - listOf( + category = SponsorCategory.Category.SUPPORT, + index = 3, + sponsors = listOf( Sponsor( - "name2", - "url2", - "image2" + name = "deploygate", + url = "https://deploygate.com/", + image = "https://droidkaigi.jp/2019/images/sponsors/42_deploygate.png" ) ) ), SponsorCategory( - SponsorCategory.Category.SUPPORT, - 3, - listOf( + category = SponsorCategory.Category.TECH, + index = 4, + sponsors = listOf( Sponsor( - "name3", - "url3", - "image3" + name = "dwango", + url = "http://dwango.co.jp/", + image = "https://droidkaigi.jp/2019/images/sponsors/58_dwango.png" ) ) ) diff --git a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/actioncreator/SponsorActionCreatorTest.kt b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/actioncreator/SponsorActionCreatorTest.kt new file mode 100644 index 000000000..e3c754c74 --- /dev/null +++ b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/actioncreator/SponsorActionCreatorTest.kt @@ -0,0 +1,53 @@ +package io.github.droidkaigi.confsched2019.sponsor.ui.actioncreator + +import androidx.lifecycle.Lifecycle +import io.github.droidkaigi.confsched2019.action.Action +import io.github.droidkaigi.confsched2019.data.repository.SponsorRepository +import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher +import io.github.droidkaigi.confsched2019.dummySponsorCategoriesData +import io.github.droidkaigi.confsched2019.ext.android.CoroutinePlugin +import io.github.droidkaigi.confsched2019.model.LoadingState +import io.github.droidkaigi.confsched2019.widget.component.TestLifecycleOwner +import io.mockk.MockKAnnotations +import io.mockk.Ordering +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.impl.annotations.RelaxedMockK +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.junit.Test + +class SponsorActionCreatorTest { + @RelaxedMockK lateinit var dispatcher: Dispatcher + @RelaxedMockK lateinit var sponsorRepository: SponsorRepository + + @Before + fun setUp() { + MockKAnnotations.init(this, relaxUnitFun = true) + CoroutinePlugin.mainDispatcherHandler = { Dispatchers.Default } + } + + @Test + fun load() = runBlocking { + val lifecycleOwner = TestLifecycleOwner().handleEvent(Lifecycle.Event.ON_RESUME) + coEvery { sponsorRepository.sponsors() } returns dummySponsorCategoriesData() + val sponsorActionCreator = SponsorActionCreator( + dispatcher, + sponsorRepository, + lifecycleOwner.lifecycle + ) + + sponsorActionCreator.load() + + coVerify(ordering = Ordering.ORDERED) { + dispatcher.dispatch(Action.SponsorLoadingStateChanged(LoadingState.LOADING)) + sponsorRepository.sponsors() + dispatcher.dispatch(Action.SponsorLoaded(dummySponsorCategoriesData())) + sponsorRepository.refresh() + sponsorRepository.sponsors() + dispatcher.dispatch(Action.SponsorLoaded(dummySponsorCategoriesData())) + dispatcher.dispatch(Action.SponsorLoadingStateChanged(LoadingState.LOADED)) + } + } +} diff --git a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/store/SponsorStoreTest.kt b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/store/SponsorStoreTest.kt index eb44d3745..cae9c8b12 100644 --- a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/store/SponsorStoreTest.kt +++ b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/sponsor/ui/store/SponsorStoreTest.kt @@ -3,7 +3,7 @@ package io.github.droidkaigi.confsched2019.sponsor.ui.store import androidx.arch.core.executor.testing.InstantTaskExecutorRule import io.github.droidkaigi.confsched2019.action.Action import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher -import io.github.droidkaigi.confsched2019.dummySponsorsData +import io.github.droidkaigi.confsched2019.dummySponsorCategoriesData import io.github.droidkaigi.confsched2019.ext.android.CoroutinePlugin import io.github.droidkaigi.confsched2019.ext.android.changedForever import io.github.droidkaigi.confsched2019.model.SponsorCategory @@ -45,7 +45,7 @@ class SponsorStoreTest { sponsorStore.sponsors.changedForever(observer) verify { observer(emptyList()) } - val dummySponsors = dummySponsorsData() + val dummySponsors = dummySponsorCategoriesData() dispatcher.dispatch( Action.SponsorLoaded(dummySponsors) ) diff --git a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/widget/ExampleUnitTest.java b/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/widget/ExampleUnitTest.java deleted file mode 100644 index 427916534..000000000 --- a/feature/sponsor/src/test/java/io/github/droidkaigi/confsched2019/widget/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.droidkaigi.confsched2019.widget; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -}