Skip to main content
Glama
SocketUtilsTest.kt1.76 kB
import io.mockk.every import io.mockk.mockkStatic import maestro.utils.SocketUtils import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import java.net.Inet4Address import java.net.InetAddress import java.net.NetworkInterface import java.util.* class SocketUtilsTest { private fun <T> List<T>.toEnumeration(): Enumeration<T> = Collections.enumeration(this) @Test fun `nextFreePort should return a free port within the specified range`() { val from = 5000 val to = 5100 val port = SocketUtils.nextFreePort(from, to) assertTrue(port in from..to) } @Test fun `nextFreePort should throw IllegalStateException when no ports are available in the range`() { val from = 100000 val to = 100010 assertThrows(IllegalStateException::class.java) { SocketUtils.nextFreePort(from, to) } } @Test fun `localIp should return local IP address`() { val ip = SocketUtils.localIp() assertNotNull(ip) assertTrue(ip.startsWith("192") || ip.startsWith("10") || ip.startsWith("172") || ip.startsWith("127")) assertTrue(InetAddress.getByName(ip) is Inet4Address) } @Test fun `localIp should return localhost address if no network interfaces are available`() { mockkStatic(NetworkInterface::class) every { NetworkInterface.getNetworkInterfaces() } returns listOf<NetworkInterface>().toEnumeration() val ip = SocketUtils.localIp() assertEquals(InetAddress.getLocalHost().hostAddress, ip) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server