Skip to content

Commit e2c2f03

Browse files
authored
Merge pull request #152 from kohlschuetter/ck/issue/144
test: Fix tests on Java 21 or newer; replace InetAddress mocking code
2 parents 24b0922 + 7d7a190 commit e2c2f03

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

core/src/test/java/org/dcache/nfs/InetAddressMatcherTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
package org.dcache.nfs;
2121

2222
import static com.google.common.net.InetAddresses.forString;
23-
import static org.junit.Assert.*;
24-
import static org.mockito.BDDMockito.given;
25-
import static org.mockito.Mockito.*;
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertFalse;
25+
import static org.junit.Assert.assertTrue;
2626

2727
import java.net.InetAddress;
2828
import java.net.UnknownHostException;
@@ -164,11 +164,6 @@ public void testDomainNoMatch() throws UnknownHostException {
164164
}
165165

166166
private InetAddress mockInetAddress(String dnsName, String... ips) throws UnknownHostException {
167-
168-
InetAddress mockedAddress = mock(InetAddress.class);
169-
given(mockedAddress.getHostName()).willReturn(dnsName);
170-
given(mockedAddress.getCanonicalHostName()).willReturn(dnsName);
171-
172-
return mockedAddress;
167+
return InetAddress.getByAddress(dnsName, InetAddress.getByName(ips[0]).getAddress());
173168
}
174169
}

core/src/test/java/org/dcache/testutils/InetAddressBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.dcache.testutils;
22

33
import java.net.InetAddress;
4-
5-
import org.mockito.Mockito;
4+
import java.net.UnknownHostException;
65

76
public class InetAddressBuilder {
87
private String ipAddress;
@@ -19,9 +18,10 @@ public InetAddressBuilder hostName(String hostName) {
1918
}
2019

2120
public InetAddress build() {
22-
InetAddress address = Mockito.mock(InetAddress.class);
23-
Mockito.when(address.getHostAddress()).thenReturn(ipAddress);
24-
Mockito.when(address.getHostName()).thenReturn(hostName);
25-
return address;
21+
try {
22+
return InetAddress.getByAddress(hostName, InetAddress.getByName(ipAddress).getAddress());
23+
} catch (UnknownHostException e) {
24+
throw new IllegalStateException(e);
25+
}
2626
}
2727
}

0 commit comments

Comments
 (0)