try {
socket = new ServerSocket();
socket.setReuseAddress(true);
- socket.bind(new InetSocketAddress(0));
+ socket.bind(new InetSocketAddress("localhost", 0));
return socket.getLocalPort();
} catch (IOException e) {
}
}
});
- SocketAddress address = socketConnection.connect(new InetSocketAddress(0));
+ SocketAddress address = socketConnection.connect(new InetSocketAddress("localhost", 0));
- baseUrl = "http://0.0.0.0:" + ((InetSocketAddress) address).getPort();
+ baseUrl = String.format("http://%s:%d", ((InetSocketAddress) address).getAddress().getHostAddress(), ((InetSocketAddress) address).getPort());
}
@AfterClass
File toFile = new File(toDir, "downloadToFile.txt");
try {
- int port = new InetSocketAddress(0).getPort();
+ int port = new InetSocketAddress("localhost", 0).getPort();
new DefaultHttpDownloader(new Settings()).download(new URI("http://localhost:" + port), toFile);
} catch (SonarException e) {
assertThat(toFile).doesNotExist();