Skip to content

Commit 77e5a86

Browse files
committed
Add UploadServiceFacade for testability
1 parent ffca6ef commit 77e5a86

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

WordPress/src/main/java/org/wordpress/android/ui/uploads/LocalDraftUploadStarter.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class LocalDraftUploadStarter @Inject constructor(
3232
private val context: Context,
3333
private val postStore: PostStore,
3434
private val siteStore: SiteStore,
35-
/**
36-
* The Coroutine dispatcher used for querying in FluxC.
37-
*/
3835
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
36+
private val uploadServiceFacade: UploadServiceFacade,
3937
private val networkUtilsWrapper: NetworkUtilsWrapper,
4038
connectionStatus: LiveData<ConnectionStatus>
4139
) : CoroutineScope {
@@ -76,10 +74,15 @@ class LocalDraftUploadStarter @Inject constructor(
7674

7775
private fun upload(scope: CoroutineScope, site: SiteModel) = scope.launch(Dispatchers.IO) {
7876
postStore.getLocalDraftPosts(site)
79-
.filterNot { UploadService.isPostUploadingOrQueued(it) }
77+
.filterNot { uploadServiceFacade.isPostUploadingOrQueued(it) }
8078
.forEach { localDraft ->
81-
val intent = UploadService.getUploadPostServiceIntent(context, localDraft, false, false, true)
82-
context.startService(intent)
79+
uploadServiceFacade.uploadPost(
80+
context = context,
81+
post = localDraft,
82+
trackAnalytics = false,
83+
publish = false,
84+
isRetry = true
85+
)
8386
}
8487
}
8588
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.wordpress.android.ui.uploads
2+
3+
import android.content.Context
4+
import org.wordpress.android.fluxc.model.PostModel
5+
import javax.inject.Inject
6+
7+
/**
8+
* An injectable class built on top of [UploadService].
9+
*
10+
* The main purpose of this is to provide testability for classes that use [UploadService]. This should never
11+
* contain any static methods.
12+
*/
13+
class UploadServiceFacade @Inject constructor() {
14+
fun uploadPost(context: Context, post: PostModel, trackAnalytics: Boolean, publish: Boolean, isRetry: Boolean) {
15+
val intent = UploadService.getUploadPostServiceIntent(context, post, trackAnalytics, publish, isRetry)
16+
context.startService(intent)
17+
}
18+
19+
fun isPostUploadingOrQueued(post: PostModel) = UploadService.isPostUploadingOrQueued(post)
20+
}

0 commit comments

Comments
 (0)