Skip to content

Instantly share code, notes, and snippets.

View DiegoGSantos's full-sized avatar

Diego Santos DiegoGSantos

  • will bank
  • Ribeirão Preto
View GitHub Profile
Espresso.closeSoftKeyboard();
@Test
fun testLoginSuccess() {
val loginRobot = LoginRobot()
loginRobot
.submit()
.assertUsernameError(R.string.required_field)
.assertPasswordError(R.string.required_field)
.inputUser("valid")
.submit()
.assertPasswordError(R.string.required_field)
class ScreenRobot {
fun enterTextIntoView(@IdRes viewId: Int, text: String): T {
onView(withId(viewId)).perform(typeText(text))
closeKeyboard()
return this as T
}
}
class LoginRobot: ScreenRobot() {
fun inputPassword(pass: String): LoginRobot {
return enterTextIntoView(LOGIN_PASSWORD, pass)
onView(withId(R.id.error_text)).check(matches(isDisplayed()));
onView(withId(R.id.login_button)).perform(click())
@DiegoGSantos
DiegoGSantos / espresso_matcher.kt
Created July 29, 2019 01:32
Espresso Android
onView(withId(R.id.login_username))
@DiegoGSantos
DiegoGSantos / Fibonacci.kt
Last active May 23, 2019 01:55
A function to get next fibonacci series
var hashMap = HashMap<Int, Long>()
private fun fibonacci(i: Long): Long {
if(hashMap.containsKey(i)) {
return hashMap[i] ?: 0
}
var result: Long = if (i <= 2) 1 else fibonacci(i - 1) + fibonacci(i - 2)
hashMap[i] = result
@RunWith(AndroidJUnit4::class)
class ProfileFragmentTest : BaseInstrumentedTest() {
@Rule
var mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
@Mock
internal var permissionManagerMock: PermissionManager? = null
@Before
fun setup() {
import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build
import android.support.v4.app.ActivityCompat
class PermissionManager {
fun isStoragePermissionGranted(context: Activity): Boolean {
return if (Build.VERSION.SDK_INT >= 23) {
class Activity {
val permissionManager: PermissionManager
fun selectImage() {
if (permissionManager.isStoragePermissionGranted(this)) {
getImage()
} else {
askPermission()
}
}