From 1a5af1e7694b20f5c1819e4c1bc305fc7cd94444 Mon Sep 17 00:00:00 2001 From: rehan Date: Fri, 11 Oct 2024 13:46:00 +0530 Subject: [PATCH] feat: enhance BrokenHttpLinksCheckerSpec to resolve from a list of hostnames - progress towards fixing #331 --- .../test/dns/CustomHostNameResolver.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/htmlSanityCheck-core/src/test/java/org/aim42/htmlsanitycheck/test/dns/CustomHostNameResolver.java b/htmlSanityCheck-core/src/test/java/org/aim42/htmlsanitycheck/test/dns/CustomHostNameResolver.java index 81d65de0..84261a3e 100644 --- a/htmlSanityCheck-core/src/test/java/org/aim42/htmlsanitycheck/test/dns/CustomHostNameResolver.java +++ b/htmlSanityCheck-core/src/test/java/org/aim42/htmlsanitycheck/test/dns/CustomHostNameResolver.java @@ -3,12 +3,24 @@ import java.lang.reflect.Field; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.List; public class CustomHostNameResolver { - public static final String WIREMOCK_HOST = "my.custom.mocked.host"; + private static Object originalResolver; + private static final List hostnames = Arrays.asList( + "www.amazon.com", + "google.com", + "junit.org", + "plumelib.org", + "people.csail.mit.edu", + "arc42.org", + "mock.codes" + ); + static { try { Field implField = InetAddress.class.getDeclaredField("impl"); @@ -21,7 +33,7 @@ public class CustomHostNameResolver { public InetAddress[] resolve(String hostname) throws UnknownHostException { // Custom DNS resolution logic - if (WIREMOCK_HOST.equals(hostname)) { + if (hostnames.contains(hostname)) { return new InetAddress[]{InetAddress.getByAddress("localhost", new byte[]{127, 0, 0, 1})}; } // Fallback to original resolver using reflection