11package org.wordpress.android.ui.uploads
22
3- import androidx.lifecycle.Lifecycle
43import androidx.lifecycle.Lifecycle.Event
54import androidx.lifecycle.LifecycleRegistry
65import androidx.lifecycle.LiveData
7- import androidx.lifecycle.MutableLiveData
8- import androidx.lifecycle.ProcessLifecycleOwner
96import kotlinx.coroutines.CancellationException
107import kotlinx.coroutines.ExperimentalCoroutinesApi
118import org.assertj.core.api.Assertions
@@ -31,7 +28,6 @@ import org.wordpress.android.fluxc.action.UploadAction
3128import org.wordpress.android.fluxc.annotations.action.Action
3229import org.wordpress.android.fluxc.model.PostModel
3330import org.wordpress.android.fluxc.model.SiteModel
34- import org.wordpress.android.fluxc.model.post.PostStatus
3531import org.wordpress.android.fluxc.model.post.PostStatus.DRAFT
3632import org.wordpress.android.fluxc.model.post.PostStatus.PENDING
3733import org.wordpress.android.fluxc.model.post.PostStatus.PRIVATE
@@ -43,14 +39,20 @@ import org.wordpress.android.fluxc.store.PostStore
4339import org.wordpress.android.fluxc.store.SiteStore
4440import org.wordpress.android.fluxc.store.UploadStore
4541import org.wordpress.android.ui.posts.PostUtilsWrapper
42+ import org.wordpress.android.ui.uploads.UploadFixtures.createConnectionStatusLiveData
43+ import org.wordpress.android.ui.uploads.UploadFixtures.createLocallyChangedPostModel
44+ import org.wordpress.android.ui.uploads.UploadFixtures.createMockedNetworkUtilsWrapper
45+ import org.wordpress.android.ui.uploads.UploadFixtures.createMockedPostUtilsWrapper
46+ import org.wordpress.android.ui.uploads.UploadFixtures.createMockedProcessLifecycleOwner
47+ import org.wordpress.android.ui.uploads.UploadFixtures.createMockedUploadServiceFacade
48+ import org.wordpress.android.ui.uploads.UploadFixtures.createMockedUploadStore
49+ import org.wordpress.android.ui.uploads.UploadFixtures.createSiteModel
50+ import org.wordpress.android.ui.uploads.UploadFixtures.resetTestPostIdIndex
4651import org.wordpress.android.util.DateTimeUtils
47- import org.wordpress.android.util.NetworkUtilsWrapper
4852import org.wordpress.android.viewmodel.helpers.ConnectionStatus
4953import org.wordpress.android.viewmodel.helpers.ConnectionStatus.AVAILABLE
5054import org.wordpress.android.viewmodel.helpers.ConnectionStatus.UNAVAILABLE
5155import java.util.Date
52- import java.util.UUID
53- import kotlin.random.Random
5456
5557@ExperimentalCoroutinesApi
5658@RunWith(MockitoJUnitRunner ::class )
@@ -480,7 +482,7 @@ class UploadStarterTest : BaseUnitTest() {
480482 val postModel = createLocallyChangedPostModel()
481483 defaultSetup(siteModel, postModel)
482484
483- // Set autosaveModified to a newer date than dateLocallyChanged to indicate the changes were remotely-auto-saved
485+ // Set autoSaveModified to a newer date than dateLocallyChanged to indicate the changes were remotely-auto-saved
484486 postModel.setAutoSaveModified(
485487 DateTimeUtils .iso8601FromTimestamp(
486488 DateTimeUtils .timestampFromIso8601(
@@ -543,51 +545,5 @@ class UploadStarterTest : BaseUnitTest() {
543545 uploadActionUseCase = UploadActionUseCase (uploadStore, postUtilsWrapper, uploadServiceFacade),
544546 tracker = mock(),
545547 dispatcher = dispatcher
546- )
547-
548- private companion object Fixtures {
549-
550- var postIdIndex = 0
551- fun makePostTitleFromId () = postIdIndex.toString().padStart(2 , ' 0' )
552-
553- fun createMockedNetworkUtilsWrapper () = mock<NetworkUtilsWrapper > {
554- on { isNetworkAvailable() } doReturn true
555- }
556-
557- fun createConnectionStatusLiveData (initialValue : ConnectionStatus ? ): MutableLiveData <ConnectionStatus > {
558- return MutableLiveData <ConnectionStatus >().apply {
559- value = initialValue
560- }
561- }
562-
563- fun createMockedPostUtilsWrapper () = mock<PostUtilsWrapper > {
564- on { isPublishable(any()) } doReturn true
565- on { isPostInConflictWithRemote(any()) } doReturn false
566- }
567-
568- fun createMockedUploadStore (numberOfAutoUploadAttempts : Int ) = mock<UploadStore > {
569- on { getNumberOfPostAutoUploadAttempts(any()) } doReturn numberOfAutoUploadAttempts
570- }
571-
572- fun createMockedUploadServiceFacade () = mock<UploadServiceFacade > {
573- on { isPostUploadingOrQueued(any()) } doReturn false
574- }
575-
576- fun createMockedProcessLifecycleOwner (lifecycle : Lifecycle = mock()) = mock<ProcessLifecycleOwner > {
577- on { this .lifecycle } doReturn lifecycle
578- }
579-
580- fun createLocallyChangedPostModel (postStatus : PostStatus = DRAFT , page : Boolean = false) = PostModel ().apply {
581- setId(++ postIdIndex)
582- setTitle(makePostTitleFromId())
583- setStatus(postStatus.toString())
584- setIsLocallyChanged(true )
585- setDateLocallyChanged(DateTimeUtils .iso8601FromTimestamp(Date ().time / 1000 ))
586- setIsPage(page)
587- }
588-
589- fun createSiteModel (isWpCom : Boolean = true) = SiteModel ().apply {
590- setIsWPCom(isWpCom)
591- }
592- }
548+ ).also { resetTestPostIdIndex() }
593549}
0 commit comments