Skip to content

Commit 52a46c0

Browse files
authored
all: smoother network utils protocol testing (fixes #12242) (#12164)
1 parent 154f829 commit 52a46c0

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "org.ole.planet.myplanet"
1313
minSdk = 26
1414
targetSdk = 36
15-
versionCode = 4988
16-
versionName = "0.49.88"
15+
versionCode = 4989
16+
versionName = "0.49.89"
1717
ndkVersion = '26.3.11579264'
1818
vectorDrawables.useSupportLibrary = true
1919
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.ole.planet.myplanet.utils
2+
3+
import dagger.hilt.android.testing.HiltAndroidRule
4+
import dagger.hilt.android.testing.HiltAndroidTest
5+
import dagger.hilt.android.testing.HiltTestApplication
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Assert.assertNull
8+
import org.junit.Before
9+
import org.junit.Rule
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
import org.robolectric.RobolectricTestRunner
13+
import org.robolectric.annotation.Config
14+
import org.robolectric.annotation.LooperMode
15+
16+
@HiltAndroidTest
17+
@RunWith(RobolectricTestRunner::class)
18+
@Config(application = HiltTestApplication::class, sdk = [33])
19+
@LooperMode(LooperMode.Mode.PAUSED)
20+
class NetworkUtilsTest {
21+
22+
@get:Rule
23+
val hiltRule = HiltAndroidRule(this)
24+
25+
@Before
26+
fun init() {
27+
hiltRule.inject()
28+
}
29+
30+
@Test
31+
fun extractProtocol_withHttpUrl() {
32+
assertEquals("http://", NetworkUtils.extractProtocol("http://example.com"))
33+
}
34+
35+
@Test
36+
fun extractProtocol_withHttpsUrl() {
37+
assertEquals("https://", NetworkUtils.extractProtocol("https://example.com/path"))
38+
}
39+
40+
@Test
41+
fun extractProtocol_withFtpUrl() {
42+
assertEquals("ftp://", NetworkUtils.extractProtocol("ftp://192.168.1.1"))
43+
}
44+
45+
@Test
46+
fun extractProtocol_withCustomScheme() {
47+
assertEquals("custom://", NetworkUtils.extractProtocol("custom://app"))
48+
}
49+
50+
@Test
51+
fun extractProtocol_withNoScheme() {
52+
assertNull(NetworkUtils.extractProtocol("example.com"))
53+
}
54+
55+
@Test
56+
fun extractProtocol_withRelativeUrl() {
57+
assertNull(NetworkUtils.extractProtocol("//example.com"))
58+
}
59+
60+
@Test
61+
fun extractProtocol_withEmptyString() {
62+
assertNull(NetworkUtils.extractProtocol(""))
63+
}
64+
}

0 commit comments

Comments
 (0)