Skip to content

Instantly share code, notes, and snippets.

Diego Santos DiegoGSantos

Block or report user

Report or block DiegoGSantos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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()
}
}
You can’t perform that action at this time.