#2661 Remove mocks of InetAddress (which is a sealed class in JDK 19)

- Remove mocks of InetAddress in favor of using real InetAddress instances. This fixes test issues under JDK 19, where InetAddress has been changed to a sealed class
This commit is contained in:
ljacqu
2022-12-30 08:27:51 +01:00
parent a14df80a87
commit 779e62674e
15 changed files with 63 additions and 45 deletions
@@ -11,13 +11,13 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Logger;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* AuthMe test utilities.
@@ -98,11 +98,14 @@ public final class TestHelper {
* @param player the player mock
* @param ip the ip address it should return
*/
public static void mockPlayerIp(Player player, String ip) {
InetAddress inetAddress = mock(InetAddress.class);
given(inetAddress.getHostAddress()).willReturn(ip);
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 8093);
given(player.getAddress()).willReturn(inetSocketAddress);
public static void mockIpAddressToPlayer(Player player, String ip) {
try {
InetAddress inetAddress = InetAddress.getByName(ip);
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 8093);
given(player.getAddress()).willReturn(inetSocketAddress);
} catch (UnknownHostException e) {
throw new IllegalStateException("Invalid IP address: " + ip, e);
}
}
/**