|
| 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