### Question:
IterativeDnsClient extends AbstractDnsClient { @Override protected DnsQueryResult query(DnsMessage.Builder queryBuilder) throws IOException { DnsMessage q = queryBuilder.build(); ResolutionState resolutionState = new ResolutionState(this); DnsQueryResult result = queryRecursive(resolutionState, q); return result; } IterativeDnsClient();  IterativeDnsClient(DnsCache cache); static List<InetAddress> getRootServer(char rootServerId); static List<InetAddress> getRootServer(char rootServerId, IpVersionSetting setting);  }### Answer:
@SuppressWarnings("unchecked") @Test public void basicIterativeTest() throws IOException { IterativeDnsClient client = new IterativeDnsClient(new LruCache(0)); applyZones(client, rootZone( record("com", ns("ns.com")), record("ns.com", a("1.1.1.1")) ), zone("com", "ns.com", "1.1.1.1", record("example.com", ns("ns.example.com")), record("ns.example.com", a("1.1.1.2")) ), zone("example.com", "ns.example.com", "1.1.1.2", record("www.example.com", a("1.1.1.3")) ) ); DnsQueryResult result = client.query("www.example.com", TYPE.A); DnsMessage message = result.response; List<Record<? extends Data>> answers = message.answerSection; assertEquals(1, answers.size()); assertEquals(TYPE.A, answers.get(0).type); assertArrayEquals(new byte[] {1, 1, 1, 3}, ((A) answers.get(0).payloadData).getIp()); }
@SuppressWarnings("unchecked") @Test public void loopIterativeTest() throws IOException { IterativeDnsClient client = new IterativeDnsClient(new LruCache(0)); applyZones(client, rootZone( record("a", ns("a.ns")), record("b", ns("b.ns")), record("a.ns", a("1.1.1.1")), record("b.ns", a("1.1.1.2")) ), zone("a", "a.ns", "1.1.1.1", record("test.a", ns("a.test.b")) ), zone("b", "b.ns", "1.1.1.2", record("test.b", ns("b.test.a")) ) ); assertThrows(IterativeClientException.LoopDetected.class, () -> client.query("www.test.a", TYPE.A) ); }
@SuppressWarnings("unchecked") @Test public void notGluedNsTest() throws IOException { IterativeDnsClient client = new IterativeDnsClient(new LruCache(0)); applyZones(client, rootZone( record("com", ns("ns.com")), record("net", ns("ns.net")), record("ns.com", a("1.1.1.1")), record("ns.net", a("1.1.2.1")) ), zone("com", "ns.com", "1.1.1.1", record("example.com", ns("example.ns.net")) ), zone("net", "ns.net", "1.1.2.1", record("example.ns.net", a("1.1.2.2")) ), zone("example.com", "example.ns.net", "1.1.2.2", record("www.example.com", a("1.1.1.3")) ) ); DnsQueryResult result = client.query("www.example.com", TYPE.A); DnsMessage message = result.response; List<Record<? extends Data>> answers = message.answerSection; assertEquals(1, answers.size()); assertEquals(TYPE.A, answers.get(0).type); assertArrayEquals(new byte[] {1, 1, 1, 3}, ((A) answers.get(0).payloadData).getIp()); }