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
import io.reactivex.subjects.PublishSubject | |
import okhttp3.MediaType | |
import okhttp3.RequestBody | |
import okio.BufferedSink | |
import java.io.File | |
import java.io.FileInputStream | |
import java.lang.Exception | |
class ProgressEmittingRequestBody constructor(val mediaType: String, val file: File) : RequestBody() { |
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
override fun contentLength(): Long { | |
return file.length() | |
} |
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
interface VideoUploadClient { | |
@POST | |
@Multipart | |
fun uploadVideoToServer(@Url url: String, | |
@PartMap body : Map<String,@JvmSuppressWildcards RequestBody>, | |
@Part video: MultipartBody.Part): Observable<ResponseBody> | |
} |
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
override fun uploadVideo(pathToVideoFile: String) : Observable<ResponseBody>{ | |
val videoFile = File(pathToVideoFile) | |
val videoRequestBody = ProgressEmittingRequestBody(mediaType = "video/*", file = videoFile) | |
val vFile = MultipartBody.Part.createFormData("file", videoFile.name, videoRequestBody) | |
val bodyMap: HashMap<String, @JvmSuppressWildcards RequestBody> = HashMap() | |
val body = responseEntity.multipartRequest.body | |
createRequestBodyMap(bodyMap, body) |
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
package com.example.coroutinesdemo.ui | |
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.viewModelScope | |
import com.example.coroutinesdemo.api.model.User | |
import com.example.coroutinesdemo.base.BaseViewModel | |
import com.example.coroutinesdemo.base.ViewStatus | |
import com.example.coroutinesdemo.repository.UserRepository | |
import kotlinx.coroutines.launch |
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
class UserViewModelTestShould{ | |
@get:Rule | |
val rule = InstantTaskExecutorRule() | |
private lateinit var viewModel: UserViewModel | |
@Mock lateinit var repository: UserRepository | |
@Mock lateinit var observer: Observer<UserViewModel.DisplayData> | |
@Before |
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
package olx.com.delorean.view.filter.viewmodel | |
import kotlinx.coroutines.CoroutineDispatcher | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.test.TestCoroutineDispatcher | |
import kotlinx.coroutines.test.TestCoroutineScope | |
import kotlinx.coroutines.test.resetMain | |
import kotlinx.coroutines.test.setMain | |
import org.junit.rules.TestWatcher | |
import org.junit.runner.Description |
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
package com.example.coroutinesdemo.ui | |
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | |
import androidx.lifecycle.Observer | |
import com.example.coroutinesdemo.api.model.User | |
import com.example.coroutinesdemo.repository.UserRepository | |
import kotlinx.coroutines.test.runBlockingTest | |
import org.junit.Before | |
import org.junit.Rule | |
import org.junit.Test |
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
@Before | |
fun setUp(){ | |
MockitoAnnotations.initMocks(this) | |
viewModel = UserViewModel(repository,dispatcherRule.testDispatcher) | |
viewModel.getData().observeForever(observer) | |
} |
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
package com.example.coroutinesdemo.base | |
import kotlinx.coroutines.CoroutineDispatcher | |
import kotlinx.coroutines.Dispatchers | |
data class CoroutineDispatcherProvider constructor( | |
val main: CoroutineDispatcher = Dispatchers.Main, | |
val default: CoroutineDispatcher = Dispatchers.Default, | |
val io: CoroutineDispatcher = Dispatchers.IO | |
) |
OlderNewer