Skip to content

Instantly share code, notes, and snippets.

Avatar

Diego Santos DiegoGSantos

  • will bank
  • Ribeirão Preto
View GitHub Profile
View espresso_test.kt
@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)
View robot_classes.kt
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)
View espresso_check.kt
onView(withId(R.id.error_text)).check(matches(isDisplayed()));
View espresso_interation.kt
onView(withId(R.id.login_button)).perform(click())
View espresso_matcher.kt
onView(withId(R.id.login_username))
@DiegoGSantos
DiegoGSantos / Fibonacci.kt
Last active May 23, 2019
A function to get next fibonacci series
View Fibonacci.kt
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
View UITest.kt
@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() {
View PermissionManager.kt
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) {
View ActivityManager.kt
class Activity {
val permissionManager: PermissionManager
fun selectImage() {
if (permissionManager.isStoragePermissionGranted(this)) {
getImage()
} else {
askPermission()
}
}