Skip to content

Commit 89c1909

Browse files
committed
Add boot completed test
1 parent 4c105b1 commit 89c1909

File tree

9 files changed

+100
-6
lines changed

9 files changed

+100
-6
lines changed

.idea/androidTestResultsUserPreferences.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,5 @@ dependencies {
158158

159159
// Android Test
160160
androidTestImplementation(libs.androidx.compose.ui.test)
161-
androidTestImplementation(libs.rules)
161+
androidTestImplementation(libs.androidx.test.rules)
162162
}

core/navigator/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ dependencies {
3333
// Test
3434

3535
testImplementation(projects.core.test)
36+
androidTestImplementation(libs.bundles.androidTest)
3637
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.w2sv.navigator.system_action_broadcastreceiver
2+
3+
import android.content.Context
4+
import androidx.test.core.app.ApplicationProvider
5+
import com.w2sv.androidutils.isServiceRunning
6+
import com.w2sv.navigator.FileNavigator
7+
import org.junit.Assert.assertTrue
8+
import org.junit.Test
9+
import java.io.BufferedReader
10+
import java.io.InputStreamReader
11+
12+
internal class BootCompletedReceiverTest {
13+
14+
private val context = ApplicationProvider.getApplicationContext<Context>()
15+
16+
@Test
17+
fun testOnReceive() {
18+
val receiver = BootCompletedReceiver()
19+
receiver.register(context)
20+
executeAdbCommand()
21+
assertTrue(context.isServiceRunning<FileNavigator>())
22+
}
23+
}
24+
25+
fun executeAdbCommand() {
26+
val adbCommand = arrayOf(
27+
"adb",
28+
"shell",
29+
"su",
30+
"root",
31+
"am",
32+
"broadcast",
33+
"-a",
34+
"android.intent.action.BOOT_COMPLETED"
35+
)
36+
37+
val processBuilder = ProcessBuilder(*adbCommand)
38+
processBuilder.redirectErrorStream(true)
39+
40+
try {
41+
val process = processBuilder.start()
42+
val reader = BufferedReader(InputStreamReader(process.inputStream))
43+
val output = StringBuilder()
44+
var line: String?
45+
46+
while (reader.readLine().also { line = it } != null) {
47+
output.append(line).append("\n")
48+
}
49+
50+
process.waitFor()
51+
52+
println("ADB Command Output: $output")
53+
assert(process.exitValue() == 0) { "ADB command failed" }
54+
} catch (e: Exception) {
55+
e.printStackTrace()
56+
assert(false) { "Exception while executing ADB command: ${e.message}" }
57+
}
58+
}

gradle/libs.versions.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protobuf = "4.27.1"
2525
androidxActivity = "1.9.0"
2626
kotlinutils = "0.1.3-rc1"
2727
datastoreutils = "0.0.3-rc1"
28+
androidXTest = "1.6.0"
2829

2930
[libraries]
3031

@@ -85,17 +86,20 @@ textflow = { module = "io.github.oleksandrbalan:textflow", version = "1.1.2" }
8586

8687
# Testing
8788
junit = { module = "junit:junit", version.ref = "junit" }
88-
androidx-junit = "androidx.test.ext:junit:1.2.0"
89+
androidx-test-junit = "androidx.test.ext:junit:1.2.0"
8990
roboelectric = "org.robolectric:robolectric:4.12.2"
90-
rules = "androidx.test:rules:1.5.0"
91+
androidx-test-core = { module = "androidx.test:core", version.ref = "androidXTest" }
92+
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidXTest" }
93+
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidXTest" }
9194

9295
# Plugins
9396
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
9497
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
9598
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
9699

97100
[bundles]
98-
unitTest = ["junit", "androidx-junit", "roboelectric"]
101+
unitTest = ["junit", "androidx-test-junit", "roboelectric"]
102+
androidTest = ["androidx-test-rules", "androidx-test-runner", "androidx-test-core"]
99103

100104
[plugins]
101105
android-application = { id = "com.android.application", version.ref = "agp" }

plugins/src/main/kotlin/BaseConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1111
internal fun Project.baseConfig() {
1212
tasks.withType<KotlinCompile>().configureEach {
1313
compilerOptions {
14-
jvmTarget.set(JvmTarget.fromTarget(libs.findVersionInt("java").toString()))
14+
jvmTarget.set(JvmTarget.fromTarget(libs.findVersionString("java")))
1515
}
1616
}
1717
extensions.configure<KotlinProjectExtension> {

plugins/src/main/kotlin/Extensions.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import org.gradle.api.artifacts.VersionCatalog
33
import org.gradle.api.artifacts.VersionCatalogsExtension
44
import org.gradle.kotlin.dsl.getByType
55

6+
internal fun VersionCatalog.findVersionString(alias: String): String =
7+
findVersion(alias).get().requiredVersion
8+
69
internal fun VersionCatalog.findVersionInt(alias: String): Int =
710
findVersion(alias).get().requiredVersion.toInt()
811

plugins/src/main/kotlin/LibraryPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class LibraryPlugin : Plugin<Project> {
88
apply(libs.findPluginId("android.library"))
99
apply(libs.findPluginId("kotlin.android"))
1010
}
11-
1211
baseConfig()
1312
}
1413
}

0 commit comments

Comments
 (0)