Skip to content

Instantly share code, notes, and snippets.

View BinarySearch.java
class Solution {
// Return tree depth in O(d) time.
public int computeDepth(TreeNode node) {
int d = 0;
while (node.left != null) {
node = node.left;
++d;
}
return d;
}
View multiple_robots.kt
@RunWith(AndroidJUnit4::class)
class CreatePostActivityTest : BaseTest() {
@Rule
@JvmField
var activityTestRule = ActivityTestRule(CreatePostActivity::class.java)
@Test
fun loging_and_createPost_WithText_Success() {
login {
View create_post_robot_image.kt
class CreatePostRobot : BaseRobot() {
fun enterPostText(text: String) =
postText().typeText(text)
fun submitPost() =
postImageView().click()
fun matchResultText(expectedText: String) =
postSubmitResultText().isTextDisplayed(expectedText)
View activity_test.kt
@RunWith(AndroidJUnit4::class)
class CreatePostActivityTest : BaseTest() {
@Rule
@JvmField
var activityTestRule = ActivityTestRule(CreatePostActivity::class.java)
@Test
fun createPost_WithText_Success() {
createPost {
View create_post_robot.kt
class CreatePostRobot : BaseRobot() {
fun enterPostText(text: String) =
postText().typeText(text)
fun submitPost() =
postButton().click()
fun matchResultText(expectedText: String) =
postSubmitResultText().isTextDisplayed(expectedText)
View base_robot.kt
abstract class BaseTest {
val createPost = robotRunner(CreatePostRobot::class)
private fun <T : BaseRobot> robotRunner(cls: KClass<T>) = { func: T.() -> Unit ->
cls.createInstance().apply {
func()
}
}
}
View ext_helpers.kt
fun ViewInteraction.click(): ViewInteraction =
perform(ViewActions.click())
fun ViewInteraction.typeText(text: String): ViewInteraction =
perform(ViewActions.typeText(text), ViewActions.closeSoftKeyboard())
fun ViewInteraction.isTextDisplayed(text: String): ViewInteraction =
check(ViewAssertions.matches(ViewMatchers.withText(text)))
View espresso_test.kt
class CreatePostActivityTest {
@Test
fun void createPost_WithText_Success() {
// Find the edit text and perform typing text action
// close the keyboard after text has been entered
onView(withId(R.id.post_text))
.perform(ViewActions.typeText("This is a post"),ViewActions.closeSoftKeyboard))
// Find the submit post button and perform a click
onView(withId(R.id.post_button))
.perform(ViewActions.click())
View ui_testing_blob.kt
@Test
fun mainActivityTest() {
val bottomNavigationItemView = onView(
allOf(
withId(R.id.navigation_dashboard), withContentDescription("Dashboard"),
childAtPosition(
childAtPosition(
withId(R.id.navigation),
0
View alias_decrypt.sh
# put this in your .bashrc or .zshrc or whatever you're using
# make sure you're in the directory where the file is when running this command
alias decrypt_secrets='openssl enc -d -aes-256-cbc -in secrets.properties.enc -out secrets.properties'