Modernization of modular approach

This commit is contained in:
Sylwester Zieliński
2021-09-24 10:25:10 +02:00
parent 91b0e39f8e
commit 3ef57bf5fd
52 changed files with 943 additions and 964 deletions

View File

@@ -0,0 +1,24 @@
package no.nordicsemi.android.utils
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("no.nordicsemi.android.utils.test", appContext.packageName)
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="no.nordicsemi.android.utils">
</manifest>

View File

@@ -0,0 +1,16 @@
package no.nordicsemi.android.utils
import android.app.ActivityManager
import android.content.Context
val <T> T.exhaustive
get() = this
val String.Companion.EMPTY
get() = ""
fun Context.isServiceRunning(serviceClassName: String): Boolean {
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val services = activityManager.getRunningServices(Integer.MAX_VALUE)
return services.find { it.service.className == serviceClassName } != null
}

View File

@@ -0,0 +1,17 @@
package no.nordicsemi.android.utils
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}