Skip to content

Commit

Permalink
add test for behavior with hidden files
Browse files Browse the repository at this point in the history
  • Loading branch information
seelchen committed Jan 19, 2024
1 parent 5026eb9 commit e649b7a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BasicSearchTest {
}

every { foundFileMock.isDirectory(any()) } returns false
every { foundFileMock.isHidden } returns false
every { foundFileMock.isHidden } returns true
}

@After
Expand All @@ -84,23 +84,23 @@ class BasicSearchTest {
every { foundFileMock.path } returns filePath
every { foundFileMock.getName(any()) } returns fileName

val deepSearch = BasicSearch(
val basicSearch = BasicSearch(
"ab",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context
)

val expectedMatchRanges = listOf(0..1)

deepSearch.foundFilesLiveData.observeForever { actualResults ->
basicSearch.foundFilesLiveData.observeForever { actualResults ->
Assert.assertNotNull(actualResults)
Assert.assertEquals(listOf(foundFileMock), actualResults.map { it.file })
Assert.assertEquals(expectedMatchRanges, actualResults.map { it.matchRange })
}

runTest {
deepSearch.search()
basicSearch.search()
}
}

Expand All @@ -116,14 +116,14 @@ class BasicSearchTest {
every { foundFileMock.path } returns filePath
every { foundFileMock.getName(any()) } returns fileName

val deepSearch = BasicSearch(
val basicSearch = BasicSearch(
"ba",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context
)

deepSearch.foundFilesLiveData.observeForever { actualResults ->
basicSearch.foundFilesLiveData.observeForever { actualResults ->
Assert.assertNotNull(actualResults)
Assert.assertTrue(
"List was not empty as expected but had ${actualResults.size} elements",

Check warning on line 129 in app/src/test/java/com/amaze/filemanager/asynchronous/asynctasks/searchfilesystem/BasicSearchTest.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/test/java/com/amaze/filemanager/asynchronous/asynctasks/searchfilesystem/BasicSearchTest.kt#L129

Multiple occurrences of the same string literal within a single file detected. Prefer extracting the string literal into a property or constant.
Expand All @@ -132,7 +132,7 @@ class BasicSearchTest {
}

runTest {
deepSearch.search()
basicSearch.search()
}
}

Expand All @@ -148,14 +148,46 @@ class BasicSearchTest {
every { foundFileMock.path } returns filePath
every { foundFileMock.getName(any()) } returns fileName

val deepSearch = BasicSearch(
val basicSearch = BasicSearch(
"test",
filePath,
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context
)

basicSearch.foundFilesLiveData.observeForever { actualResults ->
Assert.assertNotNull(actualResults)
Assert.assertTrue(
"List was not empty as expected but had ${actualResults.size} elements",
actualResults.isEmpty()
)
}

runTest {
basicSearch.search()
}
}

/**
* If a file is hidden and hidden files should not be shown, it should not be added to
* [FileSearch.foundFilesLiveData]
*/
@Test
fun testMatchHiddenFile() {
val filePath = "/test/abc.txt"
val fileName = "abc.txt"

every { foundFileMock.path } returns filePath
every { foundFileMock.getName(any()) } returns fileName

val basicSearch = BasicSearch(
"ab",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
context
)

deepSearch.foundFilesLiveData.observeForever { actualResults ->
basicSearch.foundFilesLiveData.observeForever { actualResults ->
Assert.assertNotNull(actualResults)
Assert.assertTrue(
"List was not empty as expected but had ${actualResults.size} elements",
Expand All @@ -164,7 +196,7 @@ class BasicSearchTest {
}

runTest {
deepSearch.search()
basicSearch.search()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DeepSearchTest {
}

every { foundFileMock.isDirectory(any()) } returns false
every { foundFileMock.isHidden } returns false
every { foundFileMock.isHidden } returns true
}

@After
Expand All @@ -88,7 +88,7 @@ class DeepSearchTest {
val deepSearch = DeepSearch(
"ab",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context,
OpenMode.FILE
)
Expand Down Expand Up @@ -121,7 +121,7 @@ class DeepSearchTest {
val deepSearch = DeepSearch(
"ba",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context,
OpenMode.FILE
)
Expand Down Expand Up @@ -154,7 +154,7 @@ class DeepSearchTest {
val deepSearch = DeepSearch(
"test",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
EnumSet.of(SearchParameter.SHOW_HIDDEN_FILES),
context,
OpenMode.FILE
)
Expand All @@ -171,4 +171,37 @@ class DeepSearchTest {
deepSearch.search()
}
}

/**
* If a file is hidden and hidden files should not be shown, it should not be added to
* [FileSearch.foundFilesLiveData]
*/
@Test
fun testMatchHiddenFile() {
val filePath = "/test/abc.txt"
val fileName = "abc.txt"

every { foundFileMock.path } returns filePath
every { foundFileMock.getName(any()) } returns fileName

val basicSearch = DeepSearch(
"ab",
filePath,
EnumSet.noneOf(SearchParameter::class.java),
context,
OpenMode.FILE
)

basicSearch.foundFilesLiveData.observeForever { actualResults ->
Assert.assertNotNull(actualResults)
Assert.assertTrue(
"List was not empty as expected but had ${actualResults.size} elements",
actualResults.isEmpty()
)
}

runTest {
basicSearch.search()
}
}
}

0 comments on commit e649b7a

Please sign in to comment.