aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/CastLanTest.kt
blob: 8bdeed157fd76301a4f1c4187347d4b7d5d74e98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package org.meshbay.client

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.meshbay.client.cast.CastChannels.Companion.pickLan
import org.meshbay.client.cast.CastChannels.Lan
import java.net.InetAddress

/** Which address the relay is offered on, when the phone has more than one Wi-Fi. */
class CastLanTest {
    private val hotspot = Lan(InetAddress.getByName("10.105.183.74"), active = false, internet = false)
    private val home = Lan(InetAddress.getByName("192.168.1.13"), active = true, internet = true)

    @Test fun theWifiThePhoneIsOnWinsOverItsOwnHotspotListedFirst() =
        assertEquals(home.address, pickLan(listOf(hotspot, home)))

    @Test fun onMobileDataAWifiWithInternetWins() {
        val wifi = Lan(InetAddress.getByName("192.168.1.13"), active = false, internet = true)
        assertEquals(wifi.address, pickLan(listOf(hotspot, wifi)))
    }

    @Test fun aWifiWithoutInternetStillCasts() {
        val offline = Lan(InetAddress.getByName("192.168.50.2"), active = false, internet = false)
        assertEquals(offline.address, pickLan(listOf(offline)))
    }

    @Test fun noWifiNoRelay() = assertNull(pickLan(emptyList()))
}