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
Espresso.closeSoftKeyboard(); |
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
@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) |
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 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) |
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
onView(withId(R.id.error_text)).check(matches(isDisplayed())); |
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
onView(withId(R.id.login_button)).perform(click()) |
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
onView(withId(R.id.login_username)) |
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
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 |
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
@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() { |
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 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) { |
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 Activity { | |
val permissionManager: PermissionManager | |
fun selectImage() { | |
if (permissionManager.isStoragePermissionGranted(this)) { | |
getImage() | |
} else { | |
askPermission() | |
} | |
} |
NewerOlder