Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Oct 12, 2024
1 parent f24eb01 commit 928b30d
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<string name="examine_the_app_s_source_code_on_github">Examine the app\'s source code on GitHub</string>
<string name="check_out_my_other_apps">Check out my other apps</string>
<string name="support_development">Support development</string>
<string name="buy_me_a_coffee_as_a_sign_of_gratitude">Buy me a coffee as a sign of gratitude if you feel like I\'ve deserved one</string>
<string name="buy_me_a_coffee_as_a_sign_of_gratitude">Buy me a coffee as a sign of gratitude </string>
<string name="required_permissions">Required Permissions</string>
<string name="auto">Auto</string>
<string name="rate_the_app_in_the_playstore">Rate the app in the PlayStore</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class FileTypeTest {

@Test
fun testParceling() {
FileType.values.forEach { it.testParceling() }
FileType.Image.testParceling()
FileType.Video.testParceling()
FileType.Audio.testParceling()

FileType.EBook.testParceling()
FileType.PDF.testParceling()
FileType.APK.testParceling()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import com.w2sv.common.util.copy
import com.w2sv.common.util.update
import com.w2sv.domain.model.FileType
import com.w2sv.domain.model.SourceType
import com.w2sv.domain.model.movedestination.LocalDestination
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
internal class NavigatorConfigTest {

@Test
fun testEnabledDisabledFileTypes() {
fun `enabledFileTypes and disabledFileTypes`() {
val config = NavigatorConfig.default.run {
copy(
fileTypeConfigMap = fileTypeConfigMap.copy {
update(FileType.Image) {
it.copy(enabled = false)
}
update(FileType.Video) {
it.copy(enabled = false)
}
update(FileType.Audio) {
it.copy(enabled = false)
FileType.Media.values.forEach { mediaFileType ->
update(mediaFileType) { fileTypeConfig ->
fileTypeConfig.copy(enabled = false)
}
}
}
)
Expand All @@ -32,23 +32,105 @@ internal class NavigatorConfigTest {

@Test
fun testCopyWithAlteredFileTypeConfig() {
val config = NavigatorConfig.default.copyWithAlteredFileTypeConfig(FileType.Image) {
it.copy(
enabled = false,
sourceTypeConfigMap = it.sourceTypeConfigMap.copy {
update(SourceType.Screenshot) {
it.copy(enabled = false)
val config =
NavigatorConfig.default.copyWithAlteredFileTypeConfig(FileType.Image) { fileTypeConfig ->
fileTypeConfig.copy(
enabled = false,
sourceTypeConfigMap = fileTypeConfig.sourceTypeConfigMap.copy {
update(SourceType.Screenshot) {
it.copy(
enabled = false,
quickMoveDestinations = listOf(LocalDestination.parse("path/to/destination")),
autoMoveConfig = AutoMoveConfig(
enabled = true,
destination = LocalDestination.parse("path/to/auto/move/dest")
)
)
}
update(SourceType.Camera) {
it.copy(enabled = false)
}
}
update(SourceType.Camera) {
it.copy(enabled = false)
}
}
)
}
)
}

val expected = NavigatorConfig(
fileTypeConfigMap = mapOf(
FileType.Image to FileTypeConfig(
enabled = false,
sourceTypeConfigMap = mapOf(
SourceType.Camera to SourceConfig(
enabled = false,
quickMoveDestinations = emptyList(),
autoMoveConfig = AutoMoveConfig.Empty
),
SourceType.Screenshot to SourceConfig(
enabled = false,
quickMoveDestinations = listOf(LocalDestination.parse("path/to/destination")),
autoMoveConfig = AutoMoveConfig(
enabled = true,
destination = LocalDestination.parse("path/to/auto/move/dest")
)
),
SourceType.OtherApp to SourceConfig(),
SourceType.Download to SourceConfig()
)
),
FileType.Video to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Camera to SourceConfig(),
SourceType.OtherApp to SourceConfig(),
SourceType.Download to SourceConfig()
)
),
FileType.Audio to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Recording to SourceConfig(),
SourceType.OtherApp to SourceConfig(),
SourceType.Download to SourceConfig()
)
),
FileType.PDF to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Download to SourceConfig()
)
),
FileType.Text to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Download to SourceConfig()
)
),
FileType.Archive to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Download to SourceConfig()
)
),
FileType.APK to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Download to SourceConfig()
)
),
FileType.EBook to FileTypeConfig(
enabled = true,
sourceTypeConfigMap = mapOf(
SourceType.Download to SourceConfig()
)
)
),
showBatchMoveNotification = true,
disableOnLowBattery = false,
startOnBoot = false
)

assertEquals(
"NavigatorConfig(fileTypeConfigMap={Image=FileTypeConfig(enabled=false, sourceTypeConfigMap={Camera=SourceConfig(enabled=false, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Screenshot=SourceConfig(enabled=false, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Video=FileTypeConfig(enabled=true, sourceTypeConfigMap={Camera=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Audio=FileTypeConfig(enabled=true, sourceTypeConfigMap={Recording=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), PDF=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Text=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Archive=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), APK=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), EBook=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))})}, showBatchMoveNotification=true, disableOnLowBattery=false, startOnBoot=false)",
config.toString()
expected,
config
)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">

<ImageView
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="12dp"
android:contentDescription="@null"
android:src="@drawable/ic_info_outline_24"
android:tint="@color/ic_launcher_foreground" />
app:tint="@color/ic_launcher_foreground" />
</LinearLayout>
10 changes: 8 additions & 2 deletions core/test/src/main/kotlin/com/w2sv/test/Parcelable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import org.junit.Assert.assertEquals
*/
inline fun <reified T : Parcelable> T.testParceling(flags: Int = 0) {
val parcel = Parcel.obtain()
writeToParcel(parcel, flags)
this.writeToParcel(parcel, flags)

// Reset the parcel's position for reading
parcel.setDataPosition(0)

assertEquals(this, parcelableCreator<T>().createFromParcel(parcel))
// Assert that the original and recreated objects are equal
val recreated = parcelableCreator<T>().createFromParcel(parcel)
assertEquals(this, recreated)

// Recycle the parcel to avoid memory leaks
parcel.recycle()
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ androidx-test-rules = "androidx.test:rules:1.6.1"
androidx-test-runner = "androidx.test:runner:1.6.2"
androidx-test-ext-junit = "androidx.test.ext:junit:1.2.1"
#androidx-test-uiautomator = "androidx.test.uiautomator:uiautomator:2.3.0"
roboelectric = "org.robolectric:robolectric:4.12.2"
roboelectric = "org.robolectric:robolectric:4.13"
mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:5.4.0"
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }

Expand Down

0 comments on commit 928b30d

Please sign in to comment.