@Test(expectedExceptions = { RuntimeException.class, BindException.class }, expectedExceptionsMessageRegExp = ".* Address already in use.*")

public void testCreateErrorUsedPort() throws IOException {
    int port = 18181;
    try (Socket socket = new Socket()) {
        socket.bind(new InetSocketAddress(port));
        setProperty(PrometheusMetricFactory.HTTP_SERVER_ENABLE_PROP, "true");
        setProperty(PrometheusMetricFactory.HTTP_SERVER_PORT_PROP, String.valueOf(port));
        new PrometheusMetricFactory().create();
        clearProperty(PrometheusMetricFactory.HTTP_SERVER_ENABLE_PROP);
        clearProperty(PrometheusMetricFactory.HTTP_SERVER_PORT_PROP);
    }
}