Skip to content

Instantly share code, notes, and snippets.

View mobile-pablo's full-sized avatar
🔨
Creating, Perfecting, any with -ing

Paweł Łukasz mobile-pablo

🔨
Creating, Perfecting, any with -ing
View GitHub Profile
@mobile-pablo
mobile-pablo / EspressoIdlingResource.kt
Last active May 29, 2022 20:07
Download data with Espresso_Idling_Resource
object EspressoIdlingResource {
private const val RESOURCE = "GLOBAL"
@JvmField val countingIdlingResource = CountingIdlingResource(RESOURCE)
fun increment() {
countingIdlingResource.increment()
}
@mobile-pablo
mobile-pablo / CameraTest.kt
Created May 28, 2022 15:06
Testing Camera Intent
class CameraTest {
@get: Rule
val intentsTestRule = IntentsTestRule(MainActivity::class.java)
@Test
fun test_cameraIntent_isBitmapSetToImageView() {
val activityResult = createWantedImage()
val exceptedIntent: Matcher<Intent> = hasAction(MediaStore.ACTION_IMAGE_CAPTURE)
intending(exceptedIntent).respondWith(activityResult)
@mobile-pablo
mobile-pablo / GalleryPickerTest.kt
Last active May 28, 2022 15:06
Testing Gallery Picker Intent
@RunWith(AndroidJUnit4ClassRunner::class)
class GalleryPickerTest {
@get:Rule
val intentTestRule = IntentsTestRule(MainActivity::class.java)
@Test
fun test_validateGalleryIntent() {
val exceptedIntent: Matcher<Intent> = allOf(
hasAction(Intent.ACTION_PICK),
@mobile-pablo
mobile-pablo / LoginViewModel.kt
Created October 13, 2021 21:21
Handle error and Success with Sealed class
private fun sendMessage(msg: String?, email: String, password: String) {
errorJob?.cancel()
errorJob = viewModelScope.launch {
msg?.let {
resultEvent.send(ResultEvent.Error(msg))
} ?: kotlin.run {
//We don't send Success here because We need to check Login
loginUser(email, password)
}
}