Skip to content

Instantly share code, notes, and snippets.

@Senemix29
Last active March 18, 2021 03:03
Show Gist options
  • Select an option

  • Save Senemix29/e97ede445c5f7063ddd03e45c89622be to your computer and use it in GitHub Desktop.

Select an option

Save Senemix29/e97ede445c5f7063ddd03e45c89622be to your computer and use it in GitHub Desktop.

Revisions

  1. Senemix29 renamed this gist Mar 18, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Senemix29 revised this gist Mar 18, 2021. 2 changed files with 0 additions and 30 deletions.
    7 changes: 0 additions & 7 deletions FileUtils.kt
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    class FileUtils {
    fun getDirectoryFilesListSize(context: Context, fileDirectory: String): Int {
    val directory = File(context.filesDir, fileDirectory)
    val fileList = directory.listFiles().orEmpty()
    return fileList.size
    }
    }
    23 changes: 0 additions & 23 deletions FileUtilsTest.kt
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    @Test
    fun shouldReturnNumberOfFilesInsideADirectory() {
    //Given
    val bananaDirectory = "bananas"
    createFileAtInternalDirectory(context, bananaDirectory, "prata")
    createFileAtInternalDirectory(context, bananaDirectory, "d'agua")
    createFileAtInternalDirectory(context, bananaDirectory, "nanica")

    //When
    val directoryFileListSize =
    FileUtils().getInternalDirectoryFilesListSize(context, bananaDirectory)

    //Then
    assertEquals(3, directoryFileListSize)

    }

    fun createFileAtInternalDirectory(context: Context, fileDirectory: String, fileName: String) {
    val path = "${context.filesDir}/$fileDirectory"
    val newDir = File(path).also { it.mkdirs() }
    val newFile = File(newDir, fileName)
    newFile.appendText("")
    }
  3. Senemix29 created this gist Mar 18, 2021.
    11 changes: 11 additions & 0 deletions DummyActivityTest.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    @Test
    fun shouldEnableButtonWhenValidMessageIsTyped() {
    onView(withId(R.id.messageField)).perform(typeText("you do not talk about Fight Club"))
    onView(withId(R.id.sendButton)).check(matches(isEnabled()))
    }

    @Test
    fun shouldNotEnableButtonWhenInvalidMessageIsTyped() {
    onView(withId(R.id.messageField)).perform(typeText("Hey, let me tell you about the Fight Club"))
    onView(withId(R.id.sendButton)).check(matches(not(isEnabled())))
    }
    7 changes: 7 additions & 0 deletions FileUtils.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    class FileUtils {
    fun getDirectoryFilesListSize(context: Context, fileDirectory: String): Int {
    val directory = File(context.filesDir, fileDirectory)
    val fileList = directory.listFiles().orEmpty()
    return fileList.size
    }
    }
    23 changes: 23 additions & 0 deletions FileUtilsTest.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    @Test
    fun shouldReturnNumberOfFilesInsideADirectory() {
    //Given
    val bananaDirectory = "bananas"
    createFileAtInternalDirectory(context, bananaDirectory, "prata")
    createFileAtInternalDirectory(context, bananaDirectory, "d'agua")
    createFileAtInternalDirectory(context, bananaDirectory, "nanica")

    //When
    val directoryFileListSize =
    FileUtils().getInternalDirectoryFilesListSize(context, bananaDirectory)

    //Then
    assertEquals(3, directoryFileListSize)

    }

    fun createFileAtInternalDirectory(context: Context, fileDirectory: String, fileName: String) {
    val path = "${context.filesDir}/$fileDirectory"
    val newDir = File(path).also { it.mkdirs() }
    val newFile = File(newDir, fileName)
    newFile.appendText("")
    }