From 5439fb67b01f5f4deade8d3a9c7bbf645f239255 Mon Sep 17 00:00:00 2001 From: Thierry De Leeuw Date: Wed, 11 Sep 2024 22:16:37 +0200 Subject: [PATCH] Issue #52: - Remove deprecated code - upgrade dependencies (amongst other to fix CVE) - fix typos - fix tests expected result based on current results from IPInfo - ordered the parameters correctly - add comment for failed test case to know which test is failing --- pom.xml | 22 +- src/main/java/io/ipinfo/api/IPinfo.java | 71 +++-- .../io/ipinfo/api/request/BaseRequest.java | 7 +- .../java/io/ipinfo/api/request/IPRequest.java | 5 +- .../io/ipinfo/api/request/MapRequest.java | 2 +- src/test/java/io/ipinfo/IPinfoTest.java | 245 +++++++++--------- 6 files changed, 172 insertions(+), 180 deletions(-) diff --git a/pom.xml b/pom.xml index 8f6639d..80b5031 100644 --- a/pom.xml +++ b/pom.xml @@ -68,31 +68,31 @@ com.google.code.gson gson - 2.9.0 + 2.11.0 compile com.squareup.okhttp3 okhttp - 4.10.0 + 4.12.0 compile com.google.guava guava - 32.1.2-jre + 33.3.0-jre compile org.junit.jupiter junit-jupiter-api - 5.2.0 + 5.11.0 test org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.11.0 test @@ -108,7 +108,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh @@ -119,7 +119,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 17 @@ -127,7 +127,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.1 attach-sources @@ -141,7 +141,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.10.0 attach-javadocs @@ -154,7 +154,7 @@ org.apache.maven.plugins maven-release-plugin - 3.0.1 + 3.1.0 deploy @@ -162,7 +162,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.5 sign-artifacts diff --git a/src/main/java/io/ipinfo/api/IPinfo.java b/src/main/java/io/ipinfo/api/IPinfo.java index 4cc4f9e..7e662f5 100644 --- a/src/main/java/io/ipinfo/api/IPinfo.java +++ b/src/main/java/io/ipinfo/api/IPinfo.java @@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; public class IPinfo { private static final int batchMaxSize = 1000; @@ -35,6 +34,7 @@ public class IPinfo { .setTimeoutPerBatch(batchReqTimeoutDefault) .build(); private final static Gson gson = new Gson(); + private static final MediaType JSON = MediaType.parse("application/json"); private final OkHttpClient client; private final Context context; @@ -215,7 +215,7 @@ private ConcurrentHashMap getBatchGeneric( } // everything cached; exit early. - if (lookupUrls.size() == 0) { + if (lookupUrls.isEmpty()) { return result; } @@ -234,7 +234,7 @@ private ConcurrentHashMap getBatchGeneric( } // prep URL we'll target. - // add `filter=1` as qparam for filtering out empty results on server. + // add `filter=1` as param for filtering out empty results on server. String postUrl; if (opts.filter) { postUrl = "https://ipinfo.io/batch?filter=1"; @@ -243,7 +243,7 @@ private ConcurrentHashMap getBatchGeneric( } // prepare latch & common request. - // each request, when complete, will countdown the latch. + // each request, when complete, will count down the latch. CountDownLatch latch = new CountDownLatch((int)Math.ceil(lookupUrls.size()/1000.0)); Request.Builder reqCommon = new Request.Builder() .url(postUrl) @@ -261,7 +261,7 @@ private ConcurrentHashMap getBatchGeneric( // prepare & queue up request. String urlListJson = gson.toJson(urlsChunk); - RequestBody requestBody = RequestBody.create(null, urlListJson); + RequestBody requestBody = RequestBody.create(urlListJson, JSON); Request req = reqCommon.post(requestBody).build(); OkHttpClient chunkClient = client.newBuilder() .connectTimeout(timeoutPerBatch, TimeUnit.SECONDS) @@ -284,22 +284,19 @@ public void onResponse(Call call, Response response) throws IOException { Type respType = new TypeToken>() {}.getType(); HashMap localResult = gson.fromJson(response.body().string(), respType); - localResult.forEach(new BiConsumer() { - @Override - public void accept(String k, Object v) { - if (k.startsWith("AS")) { - String vStr = gson.toJson(v); - ASNResponse vCasted = gson.fromJson(vStr, ASNResponse.class); - vCasted.setContext(context); - result.put(k, vCasted); - } else if (InetAddresses.isInetAddress(k)) { - String vStr = gson.toJson(v); - IPResponse vCasted = gson.fromJson(vStr, IPResponse.class); - vCasted.setContext(context); - result.put(k, vCasted); - } else { - result.put(k, v); - } + localResult.forEach((key, value) -> { + if (key.startsWith("AS")) { + String vStr = gson.toJson(value); + ASNResponse vCasted = gson.fromJson(vStr, ASNResponse.class); + vCasted.setContext(context); + result.put(key, vCasted); + } else if (InetAddresses.isInetAddress(key)) { + String vStr = gson.toJson(value); + IPResponse vCasted = gson.fromJson(vStr, IPResponse.class); + vCasted.setContext(context); + result.put(key, vCasted); + } else { + result.put(key, value); } }); @@ -315,7 +312,7 @@ public void accept(String k, Object v) { } else { boolean success = latch.await(opts.timeoutTotal, TimeUnit.SECONDS); if (!success) { - if (result.size() == 0) { + if (result.isEmpty()) { return null; } else { return result; @@ -323,7 +320,7 @@ public void accept(String k, Object v) { } } } catch (InterruptedException e) { - if (result.size() == 0) { + if (result.isEmpty()) { return null; } else { return result; @@ -403,14 +400,14 @@ public static class Builder { private boolean filter = false; /** - * batchSize is the internal batch size used per API request; the IPinfo + *

batchSize is the internal batch size used per API request; the IPinfo * API has a maximum batch size, but the batch request functions available - * in this library do not. Therefore the library chunks the input slices + * in this library do not. Therefore, the library chunks the input slices * internally into chunks of size `batchSize`, clipping to the maximum - * allowed by the IPinfo API. + * allowed by the IPinfo API.

* - * 0 means to use the default batch size which is the max allowed by the - * IPinfo API. + *

0 means to use the default batch size which is the max allowed by the + * IPinfo API.

* * @param batchSize see description. * @return the builder. @@ -421,11 +418,11 @@ public Builder setBatchSize(int batchSize) { } /** - * timeoutPerBatch is the timeout in seconds that each batch of size - * `BatchSize` will have for its own request. + *

timeoutPerBatch is the timeout in seconds that each batch of size + * `BatchSize` will have for its own request.

* - * 0 means to use a default of 5 seconds; any negative number will turn it - * off; turning it off does _not_ disable the effects of `timeoutTotal`. + *

0 means to use a default of 5 seconds; any negative number will turn it + * off; turning it off does _not_ disable the effects of `timeoutTotal`.

* * @param timeoutPerBatch see description. * @return the builder. @@ -436,10 +433,10 @@ public Builder setTimeoutPerBatch(int timeoutPerBatch) { } /** - * timeoutTotal is the total timeout in seconds for all batch requests in a - * batch request function to complete. + *

timeoutTotal is the total timeout in seconds for all batch requests in a + * batch request function to complete.

* - * 0 means no total timeout; `timeoutPerBatch` will still apply. + *

0 means no total timeout; `timeoutPerBatch` will still apply.

* * @param timeoutTotal see description. * @return the builder. @@ -450,8 +447,8 @@ public Builder setTimeoutTotal(int timeoutTotal) { } /** - * filter, if turned on, will filter out a URL whose value was deemed empty - * on the server. + *

filter, if turned on, will filter out a URL whose value was deemed empty + * on the server.

* * @param filter see description. * @return the builder. diff --git a/src/main/java/io/ipinfo/api/request/BaseRequest.java b/src/main/java/io/ipinfo/api/request/BaseRequest.java index 0d9732a..d962a79 100644 --- a/src/main/java/io/ipinfo/api/request/BaseRequest.java +++ b/src/main/java/io/ipinfo/api/request/BaseRequest.java @@ -4,6 +4,7 @@ import io.ipinfo.api.errors.ErrorResponseException; import io.ipinfo.api.errors.RateLimitedException; import okhttp3.Credentials; +import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -12,6 +13,7 @@ public abstract class BaseRequest { protected final static Gson gson = new Gson(); private final OkHttpClient client; private final String token; + protected static final MediaType JSON = MediaType.parse("application/json"); protected BaseRequest(OkHttpClient client, String token) { this.client = client; @@ -34,11 +36,6 @@ public Response handleRequest(Request.Builder request) throws RateLimitedExcepti throw new ErrorResponseException(e); } - // Sanity check - if (response == null) { - return null; - } - if (response.code() == 429) { throw new RateLimitedException(); } diff --git a/src/main/java/io/ipinfo/api/request/IPRequest.java b/src/main/java/io/ipinfo/api/request/IPRequest.java index 4472f7b..c03e244 100644 --- a/src/main/java/io/ipinfo/api/request/IPRequest.java +++ b/src/main/java/io/ipinfo/api/request/IPRequest.java @@ -44,7 +44,7 @@ public IPResponse handle() throws RateLimitedException { } } - static IpAddressMatcher[] IpAddressMatcherList = { + private static final IpAddressMatcher[] IpAddressMatcherList = { // IPv4 new IpAddressMatcher("0.0.0.0/8"), new IpAddressMatcher("10.0.0.0/8"), @@ -106,8 +106,7 @@ public IPResponse handle() throws RateLimitedException { }; static boolean isBogon(String ip) { - for (int i = 0; i < IpAddressMatcherList.length; i++) { - IpAddressMatcher ipAddressMatcher = IpAddressMatcherList[i]; + for (IpAddressMatcher ipAddressMatcher : IpAddressMatcherList) { if (ipAddressMatcher.matches(ip)) { return true; } diff --git a/src/main/java/io/ipinfo/api/request/MapRequest.java b/src/main/java/io/ipinfo/api/request/MapRequest.java index 3e6baf6..d021397 100644 --- a/src/main/java/io/ipinfo/api/request/MapRequest.java +++ b/src/main/java/io/ipinfo/api/request/MapRequest.java @@ -19,7 +19,7 @@ public MapRequest(OkHttpClient client, String token, List ips) { @Override public MapResponse handle() throws RateLimitedException { String jsonIpList = gson.toJson(ips); - RequestBody requestBody = RequestBody.create(null, jsonIpList); + RequestBody requestBody = RequestBody.create(jsonIpList, JSON); Request.Builder request = new Request.Builder().url(URL).post(requestBody); try (Response response = handleRequest(request)) { diff --git a/src/test/java/io/ipinfo/IPinfoTest.java b/src/test/java/io/ipinfo/IPinfoTest.java index 0bd0fc7..37321c0 100644 --- a/src/test/java/io/ipinfo/IPinfoTest.java +++ b/src/test/java/io/ipinfo/IPinfoTest.java @@ -1,14 +1,11 @@ package io.ipinfo; import io.ipinfo.api.IPinfo; -import io.ipinfo.api.errors.ErrorResponseException; import io.ipinfo.api.errors.RateLimitedException; import io.ipinfo.api.model.ASNResponse; import io.ipinfo.api.model.IPResponse; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -26,35 +23,35 @@ public void testGoogleDNS() { try { IPResponse response = ii.lookupIP("8.8.8.8"); assertAll("8.8.8.8", - () -> assertEquals(response.getIp(), "8.8.8.8"), - () -> assertEquals(response.getHostname(), "dns.google"), - () -> assertTrue(response.getAnycast()), - () -> assertEquals(response.getCity(), "Mountain View"), - () -> assertEquals(response.getRegion(), "California"), - () -> assertEquals(response.getCountryCode(), "US"), - () -> assertEquals(response.getCountryName(), "United States"), + () -> assertEquals("8.8.8.8", response.getIp()), + () -> assertEquals("dns.google", response.getHostname()), + () -> assertTrue(response.getAnycast(), "Is anycast"), + () -> assertEquals("Mountain View", response.getCity()), + () -> assertEquals("California", response.getRegion()), + () -> assertEquals("US", response.getCountryCode()), + () -> assertEquals("United States", response.getCountryName()), () -> assertFalse(response.isEU()), - () -> assertEquals(response.getCountryFlag().getEmoji(), "🇺🇸"), - () -> assertEquals(response.getCountryFlag().getUnicode(), "U+1F1FA U+1F1F8"), - () -> assertEquals(response.getCountryFlagURL(), "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), - () -> assertEquals(response.getCountryCurrency().getCode(), "USD"), - () -> assertEquals(response.getCountryCurrency().getSymbol(), "$"), - () -> assertEquals(response.getContinent().getCode(), "NA"), - () -> assertEquals(response.getContinent().getName(), "North America"), - () -> assertEquals(response.getTimezone(), "America/Los_Angeles"), - () -> assertFalse(response.getPrivacy().getProxy()), - () -> assertFalse(response.getPrivacy().getVpn()), - () -> assertFalse(response.getPrivacy().getTor()), - () -> assertFalse(response.getPrivacy().getRelay()), - () -> assertTrue(response.getPrivacy().getHosting()), - () -> assertEquals(response.getPrivacy().getService(), ""), - () -> assertEquals(response.getDomains().getDomains().size(), 5) + () -> assertEquals("🇺🇸", response.getCountryFlag().getEmoji()), + () -> assertEquals("U+1F1FA U+1F1F8", response.getCountryFlag().getUnicode()), + () -> assertEquals("https://cdn.ipinfo.io/static/images/countries-flags/US.svg", response.getCountryFlagURL()), + () -> assertEquals("USD", response.getCountryCurrency().getCode()), + () -> assertEquals("$", response.getCountryCurrency().getSymbol()), + () -> assertEquals("NA", response.getContinent().getCode()), + () -> assertEquals("North America", response.getContinent().getName()), + () -> assertEquals("America/Los_Angeles", response.getTimezone()), + () -> assertFalse(response.getPrivacy().getProxy(), "Is proxy"), + () -> assertFalse(response.getPrivacy().getVpn(), "Is VPN"), + () -> assertFalse(response.getPrivacy().getTor(), "Is Tor"), + () -> assertFalse(response.getPrivacy().getRelay(), "Is relay"), + () -> assertTrue(response.getPrivacy().getHosting(), "Is hosting"), + () -> assertEquals("", response.getPrivacy().getService()), + () -> assertEquals(5, response.getDomains().getDomains().size()) ); IPResponse bogonResp = ii.lookupIP("2001:0:c000:200::0:255:1"); assertAll("", - () -> assertEquals(bogonResp.getIp(), "2001:0:c000:200::0:255:1"), - () -> assertTrue(bogonResp.getBogon()) + () -> assertEquals("2001:0:c000:200::0:255:1", bogonResp.getIp()), + () -> assertTrue(bogonResp.getBogon()) ); } catch (RateLimitedException e) { fail(e); @@ -81,7 +78,7 @@ public void testGetBatch() { .build(); try { - List urls = new ArrayList(10); + List urls = new ArrayList<>(10); urls.add("AS123"); urls.add("8.8.8.8"); urls.add("9.9.9.9/hostname"); @@ -94,44 +91,44 @@ public void testGetBatch() { () -> assertTrue(result.containsKey("9.9.9.9/hostname")) ); - ASNResponse asnResp = (ASNResponse)result.get("AS123"); + ASNResponse asnResp = (ASNResponse) result.get("AS123"); assertAll("AS123", - () -> assertEquals(asnResp.getAsn(), "AS123"), - () -> assertEquals(asnResp.getName(), "Air Force Systems Networking"), - () -> assertEquals(asnResp.getCountryCode(), "US"), - () -> assertEquals(asnResp.getCountryName(), "United States"), - () -> assertEquals(asnResp.getAllocated(), "1987-08-24"), - () -> assertEquals(asnResp.getRegistry(), "arin"), - () -> assertEquals(asnResp.getDomain(), "af.mil"), - () -> assertEquals(asnResp.getNumIps(), new Integer(0)), - () -> assertEquals(asnResp.getType(), "inactive") + () -> assertEquals("AS123", asnResp.getAsn()), + () -> assertEquals("Air Force Systems Networking", asnResp.getName()), + () -> assertEquals("US", asnResp.getCountryCode()), + () -> assertEquals("United States", asnResp.getCountryName()), + () -> assertEquals("1987-08-24", asnResp.getAllocated()), + () -> assertEquals("arin", asnResp.getRegistry()), + () -> assertEquals("af.mil", asnResp.getDomain()), + () -> assertEquals(Integer.valueOf(0), asnResp.getNumIps()), + () -> assertEquals("inactive", asnResp.getType()) ); - IPResponse ipResp = (IPResponse)result.get("8.8.8.8"); + IPResponse ipResp = (IPResponse) result.get("8.8.8.8"); assertAll("8.8.8.8", - () -> assertEquals(ipResp.getIp(), "8.8.8.8"), - () -> assertEquals(ipResp.getHostname(), "dns.google"), - () -> assertTrue(ipResp.getAnycast()), - () -> assertEquals(ipResp.getCity(), "Mountain View"), - () -> assertEquals(ipResp.getRegion(), "California"), - () -> assertEquals(ipResp.getCountryCode(), "US"), - () -> assertEquals(ipResp.getCountryName(), "United States"), - () -> assertEquals(ipResp.getTimezone(), "America/Los_Angeles"), - () -> assertFalse(ipResp.getPrivacy().getProxy()), - () -> assertFalse(ipResp.getPrivacy().getVpn()), - () -> assertFalse(ipResp.getPrivacy().getTor()), - () -> assertFalse(ipResp.getPrivacy().getRelay()), - () -> assertTrue(ipResp.getPrivacy().getHosting()), - () -> assertEquals(ipResp.getPrivacy().getService(), ""), - () -> assertEquals(ipResp.getDomains().getDomains().size(), 5) + () -> assertEquals("8.8.8.8", ipResp.getIp()), + () -> assertEquals("dns.google", ipResp.getHostname()), + () -> assertTrue(ipResp.getAnycast(), "Is anycast"), + () -> assertEquals("Mountain View", ipResp.getCity()), + () -> assertEquals("California", ipResp.getRegion()), + () -> assertEquals("US", ipResp.getCountryCode()), + () -> assertEquals("United States", ipResp.getCountryName()), + () -> assertEquals("America/Los_Angeles", ipResp.getTimezone()), + () -> assertFalse(ipResp.getPrivacy().getProxy(), "Is proxy"), + () -> assertFalse(ipResp.getPrivacy().getVpn(), "Is VPN"), + () -> assertFalse(ipResp.getPrivacy().getTor(), "Is Tor"), + () -> assertFalse(ipResp.getPrivacy().getRelay(), "Is relay"), + () -> assertTrue(ipResp.getPrivacy().getHosting(), "Is hosting"), + () -> assertEquals("", ipResp.getPrivacy().getService()), + () -> assertEquals(5, ipResp.getDomains().getDomains().size()) ); - String hostname = (String)result.get("9.9.9.9/hostname"); - assertEquals(hostname, "dns9.quad9.net"); + String hostname = (String) result.get("9.9.9.9/hostname"); + assertEquals("dns9.quad9.net", hostname); - IPResponse bogonResp = (IPResponse)result.get("239.0.0.0"); + IPResponse bogonResp = (IPResponse) result.get("239.0.0.0"); assertAll("239.0.0.0", - () -> assertEquals(bogonResp.getIp(), "239.0.0.0"), + () -> assertEquals("239.0.0.0", bogonResp.getIp()), () -> assertTrue(bogonResp.getBogon()) ); } catch (RateLimitedException e) { @@ -146,7 +143,7 @@ public void testGetBatchIps() { .build(); try { - List ips = new ArrayList(10); + List ips = new ArrayList<>(10); ips.add("1.1.1.1"); ips.add("8.8.8.8"); ips.add("9.9.9.9"); @@ -160,59 +157,61 @@ public void testGetBatchIps() { IPResponse res1 = result.get("1.1.1.1"); assertAll("1.1.1.1", - () -> assertEquals(res1.getIp(), "1.1.1.1"), - () -> assertEquals(res1.getHostname(), "one.one.one.one"), - () -> assertTrue(res1.getAnycast()), - () -> assertEquals(res1.getCity(), "Los Angeles"), - () -> assertEquals(res1.getRegion(), "California"), - () -> assertEquals(res1.getCountryCode(), "US"), - () -> assertEquals(res1.getCountryName(), "United States"), - () -> assertEquals(res1.getTimezone(), "America/Los_Angeles"), - () -> assertFalse(res1.getPrivacy().getProxy()), - () -> assertFalse(res1.getPrivacy().getVpn()), - () -> assertFalse(res1.getPrivacy().getTor()), - () -> assertFalse(res1.getPrivacy().getRelay()), - () -> assertTrue(res1.getPrivacy().getHosting()), - () -> assertEquals(res1.getPrivacy().getService(), ""), - () -> assertEquals(res1.getDomains().getDomains().size(), 5) + () -> assertEquals("1.1.1.1", res1.getIp()), + () -> assertEquals("one.one.one.one", res1.getHostname()), + () -> assertTrue(res1.getAnycast(), "Is anycast"), + () -> assertEquals("Jakarta", res1.getCity()), + () -> assertEquals("Jakarta", res1.getRegion()), + () -> assertEquals("ID", res1.getCountryCode()), + () -> assertEquals("Indonesia", res1.getCountryName()), + () -> assertEquals("Asia/Jakarta", res1.getTimezone()), + () -> assertFalse(res1.getPrivacy().getProxy(), "Is proxy"), + () -> assertFalse(res1.getPrivacy().getVpn(), "Is VPN"), + () -> assertFalse(res1.getPrivacy().getTor(), "Is Tor"), + () -> assertFalse(res1.getPrivacy().getRelay(), "Is relay"), + () -> assertTrue(res1.getPrivacy().getHosting(), "Is hosting"), + () -> assertEquals("", res1.getPrivacy().getService()), + () -> assertEquals(5, res1.getDomains().getDomains().size()) ); IPResponse res2 = result.get("8.8.8.8"); assertAll("8.8.8.8", - () -> assertEquals(res2.getIp(), "8.8.8.8"), - () -> assertEquals(res2.getHostname(), "dns.google"), - () -> assertTrue(res2.getAnycast()), - () -> assertEquals(res2.getCity(), "Mountain View"), - () -> assertEquals(res2.getRegion(), "California"), - () -> assertEquals(res2.getCountryCode(), "US"), - () -> assertEquals(res2.getCountryName(), "United States"), - () -> assertEquals(res2.getTimezone(), "America/Los_Angeles"), - () -> assertFalse(res2.getPrivacy().getProxy()), - () -> assertFalse(res2.getPrivacy().getVpn()), - () -> assertFalse(res2.getPrivacy().getTor()), - () -> assertFalse(res2.getPrivacy().getRelay()), - () -> assertTrue(res2.getPrivacy().getHosting()), - () -> assertEquals(res2.getPrivacy().getService(), ""), - () -> assertEquals(res2.getDomains().getDomains().size(), 5) + () -> assertEquals("8.8.8.8", res2.getIp()), + () -> assertEquals("dns.google", res2.getHostname()), + () -> assertTrue(res2.getAnycast(), "Is anycast"), + () -> assertEquals("Mountain View", res2.getCity()), + () -> assertEquals("California", res2.getRegion()), + () -> assertEquals("US", res2.getCountryCode()), + () -> assertEquals("United States", res2.getCountryName()), + () -> assertEquals("America/Los_Angeles", res2.getTimezone()), + () -> assertFalse(res2.getPrivacy().getProxy(), "Is proxy"), + () -> assertFalse(res2.getPrivacy().getVpn(), "Is VPN"), + () -> assertFalse(res2.getPrivacy().getTor(), "Is Tor"), + () -> assertFalse(res2.getPrivacy().getRelay(), "Is relay"), + () -> assertTrue(res2.getPrivacy().getHosting(), "Is hosting"), + () -> assertEquals("", res2.getPrivacy().getService()), + () -> assertEquals(5, res2.getDomains().getDomains().size()) + ); IPResponse res3 = result.get("9.9.9.9"); assertAll("9.9.9.9", - () -> assertEquals(res3.getIp(), "9.9.9.9"), - () -> assertEquals(res3.getHostname(), "dns9.quad9.net"), - () -> assertTrue(res3.getAnycast()), - () -> assertEquals(res3.getCity(), "Zürich"), - () -> assertEquals(res3.getRegion(), "Zurich"), - () -> assertEquals(res3.getCountryCode(), "CH"), - () -> assertEquals(res3.getCountryName(), "Switzerland"), - () -> assertEquals(res3.getTimezone(), "Europe/Zurich"), - () -> assertFalse(res3.getPrivacy().getProxy()), - () -> assertFalse(res3.getPrivacy().getVpn()), - () -> assertFalse(res3.getPrivacy().getTor()), - () -> assertFalse(res3.getPrivacy().getRelay()), - () -> assertFalse(res3.getPrivacy().getHosting()), - () -> assertEquals(res3.getPrivacy().getService(), ""), - () -> assertEquals(res3.getDomains().getDomains().size(), 5) + () -> assertEquals("9.9.9.9", res3.getIp()), + () -> assertEquals("dns9.quad9.net", res3.getHostname()), + () -> assertTrue(res3.getAnycast(), "Is anycast"), + () -> assertEquals("Zürich", res3.getCity()), + () -> assertEquals("Zurich", res3.getRegion()), + () -> assertEquals("CH", res3.getCountryCode()), + () -> assertEquals("Switzerland", res3.getCountryName()), + () -> assertEquals("Europe/Zurich", res3.getTimezone()), + () -> assertFalse(res3.getPrivacy().getProxy(), "Is proxy"), + () -> assertFalse(res3.getPrivacy().getVpn(), "Is VPN"), + () -> assertFalse(res3.getPrivacy().getTor(), "Is Tor"), + () -> assertFalse(res3.getPrivacy().getRelay(), "Is relay"), + () -> assertTrue(res3.getPrivacy().getHosting(), "Is hosting"), + () -> assertEquals("", res3.getPrivacy().getService()), + () -> assertEquals(5, res3.getDomains().getDomains().size()) + ); } catch (RateLimitedException e) { fail(e); @@ -226,7 +225,7 @@ public void testGetBatchAsns() { .build(); try { - List asns = new ArrayList(10); + List asns = new ArrayList<>(10); asns.add("AS123"); asns.add("AS321"); ConcurrentHashMap result = ii.getBatchAsns(asns); @@ -238,28 +237,28 @@ public void testGetBatchAsns() { ASNResponse res1 = result.get("AS123"); assertAll("AS123", - () -> assertEquals(res1.getAsn(), "AS123"), - () -> assertEquals(res1.getName(), "Air Force Systems Networking"), - () -> assertEquals(res1.getCountryCode(), "US"), - () -> assertEquals(res1.getCountryName(), "United States"), - () -> assertEquals(res1.getAllocated(), "1987-08-24"), - () -> assertEquals(res1.getRegistry(), "arin"), - () -> assertEquals(res1.getDomain(), "af.mil"), - () -> assertEquals(res1.getNumIps(), new Integer(0)), - () -> assertEquals(res1.getType(), "inactive") + () -> assertEquals("AS123", res1.getAsn()), + () -> assertEquals("Air Force Systems Networking", res1.getName()), + () -> assertEquals("US", res1.getCountryCode()), + () -> assertEquals("United States", res1.getCountryName()), + () -> assertEquals("1987-08-24", res1.getAllocated()), + () -> assertEquals("arin", res1.getRegistry()), + () -> assertEquals("af.mil", res1.getDomain()), + () -> assertEquals(Integer.valueOf(0), res1.getNumIps()), + () -> assertEquals("inactive", res1.getType()) ); ASNResponse res2 = result.get("AS321"); assertAll("AS321", - () -> assertEquals(res2.getAsn(), "AS321"), - () -> assertEquals(res2.getName(), "DoD Network Information Center"), - () -> assertEquals(res2.getCountryCode(), "US"), - () -> assertEquals(res2.getCountryName(), "United States"), - () -> assertEquals(res2.getAllocated(), "1989-06-30"), - () -> assertEquals(res2.getRegistry(), "arin"), - () -> assertEquals(res2.getDomain(), "mail.mil"), - () -> assertEquals(res2.getNumIps(), new Integer(66048)), - () -> assertEquals(res2.getType(), "business") + () -> assertEquals("AS321", res2.getAsn()), + () -> assertEquals("DoD Network Information Center", res2.getName()), + () -> assertEquals("US", res2.getCountryCode()), + () -> assertEquals("United States", res2.getCountryName()), + () -> assertEquals("1989-06-30", res2.getAllocated()), + () -> assertEquals("arin", res2.getRegistry()), + () -> assertEquals("mail.mil", res2.getDomain()), + () -> assertEquals(Integer.valueOf(66048), res2.getNumIps()), + () -> assertEquals("government", res2.getType()) ); } catch (RateLimitedException e) { fail(e);