All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mike10004.vhs.testsupport.TestsTest Maven / Gradle / Ivy

There is a newer version: 0.20
Show newest version
package io.github.mike10004.vhs.testsupport;

import com.google.common.net.HostAndPort;
import org.junit.Test;

import java.net.ServerSocket;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class TestsTest {

    @Test
    public void test_isStillAlive() throws Exception {
        HostAndPort liveAddress;
        try (ServerSocket ctrl = new ServerSocket(0)) {
            liveAddress = HostAndPort.fromParts("localhost", ctrl.getLocalPort());
            assertTrue("ctrl.getSocketAddress() alive", Tests.isStillAlive(liveAddress));
        }
        assertFalse("after closed", Tests.isStillAlive(liveAddress));
        int port = Tests.findOpenPort();
        assertFalse("unused port still alive", Tests.isStillAlive(HostAndPort.fromParts("localhost", port)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy