mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-14 03:46:25 -04:00
refactor: replace unMock with Hilt testing
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
import android.net.Uri
|
||||
import com.geeksville.mesh.model.getChannelUrl
|
||||
import com.geeksville.mesh.model.primaryChannel
|
||||
import com.geeksville.mesh.model.shouldAddChannels
|
||||
import com.geeksville.mesh.model.toChannelSet
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class ChannelSetTest {
|
||||
|
||||
@get:Rule
|
||||
var hiltRule = HiltAndroidRule(this)
|
||||
|
||||
@Before
|
||||
fun init() {
|
||||
hiltRule.inject()
|
||||
}
|
||||
|
||||
/** make sure we match the python and device code behavior */
|
||||
@Test
|
||||
fun matchPython() {
|
||||
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ")
|
||||
val cs = url.toChannelSet()
|
||||
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
||||
Assert.assertEquals(url, cs.getChannelUrl(false))
|
||||
}
|
||||
|
||||
/** validate against the host or path in a case-insensitive way */
|
||||
@Test
|
||||
fun parseCaseInsensitive() {
|
||||
var url = Uri.parse("HTTPS://MESHTASTIC.ORG/E/#CgMSAQESBggBQANIAQ")
|
||||
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
|
||||
|
||||
url = Uri.parse("HTTPS://mEsHtAsTiC.OrG/e/#CgMSAQESBggBQANIAQ")
|
||||
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
|
||||
}
|
||||
|
||||
/** properly parse channel config when `?add=true` is in the fragment */
|
||||
@Test
|
||||
fun handleAddInFragment() {
|
||||
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ?add=true")
|
||||
val cs = url.toChannelSet()
|
||||
val shouldAdd = url.shouldAddChannels()
|
||||
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
||||
Assert.assertTrue(shouldAdd)
|
||||
}
|
||||
|
||||
/** properly parse channel config when `?add=true` is in the query parameters */
|
||||
@Test
|
||||
fun handleAddInQueryParams() {
|
||||
val url = Uri.parse("https://meshtastic.org/e/?add=true#CgMSAQESBggBQANIAQ")
|
||||
val cs = url.toChannelSet()
|
||||
val shouldAdd = url.shouldAddChannels()
|
||||
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
||||
Assert.assertTrue(shouldAdd)
|
||||
}
|
||||
}
|
||||
13
app/src/androidTest/java/com/geeksville/mesh/TestRunner.kt
Normal file
13
app/src/androidTest/java/com/geeksville/mesh/TestRunner.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.test.runner.AndroidJUnitRunner
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
|
||||
@Suppress("unused")
|
||||
class TestRunner : AndroidJUnitRunner() {
|
||||
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
|
||||
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user