@Test public void testLookupMechanismOrder() { DnsClient.addDnsServerLookupMechanism(new TestDnsServerLookupMechanism(AndroidUsingExec.INSTANCE)); DnsClient.addDnsServerLookupMechanism(new TestDnsServerLookupMechanism(AndroidUsingReflection.INSTANCE)); List<DnsServerLookupMechanism> expectedOrder = new ArrayList<>(); expectedOrder.add(0, AndroidUsingExec.INSTANCE); expectedOrder.add(1, AndroidUsingReflection.INSTANCE); for (DnsServerLookupMechanism mechanism : DnsClient.LOOKUP_MECHANISMS) { if (expectedOrder.isEmpty()) { break; } DnsServerLookupMechanism shouldBeRemovedNext = expectedOrder.get(0); if (mechanism.getName().equals(shouldBeRemovedNext.getName())) { expectedOrder.remove(0); } } assertTrue(expectedOrder.isEmpty()); }
public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup) { if (!dnsServerLookup.isAvailable()) { LOGGER.fine("Not adding " + dnsServerLookup.getName() + " as it is not available."); return; } synchronized (LOOKUP_MECHANISMS) { ArrayList<DnsServerLookupMechanism> tempList = new ArrayList<>(LOOKUP_MECHANISMS.size() + 1); tempList.addAll(LOOKUP_MECHANISMS); tempList.add(dnsServerLookup); Collections.sort(tempList); LOOKUP_MECHANISMS.clear(); LOOKUP_MECHANISMS.addAll(tempList); } }
DnsClient extends AbstractDnsClient { public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup) { if (!dnsServerLookup.isAvailable()) { LOGGER.fine("Not adding " + dnsServerLookup.getName() + " as it is not available."); return; } synchronized (LOOKUP_MECHANISMS) { ArrayList<DnsServerLookupMechanism> tempList = new ArrayList<>(LOOKUP_MECHANISMS.size() + 1); tempList.addAll(LOOKUP_MECHANISMS); tempList.add(dnsServerLookup); Collections.sort(tempList); LOOKUP_MECHANISMS.clear(); LOOKUP_MECHANISMS.addAll(tempList); } } }
DnsClient extends AbstractDnsClient { public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup) { if (!dnsServerLookup.isAvailable()) { LOGGER.fine("Not adding " + dnsServerLookup.getName() + " as it is not available."); return; } synchronized (LOOKUP_MECHANISMS) { ArrayList<DnsServerLookupMechanism> tempList = new ArrayList<>(LOOKUP_MECHANISMS.size() + 1); tempList.addAll(LOOKUP_MECHANISMS); tempList.add(dnsServerLookup); Collections.sort(tempList); LOOKUP_MECHANISMS.clear(); LOOKUP_MECHANISMS.addAll(tempList); } } DnsClient();  DnsClient(DnsCache dnsCache); }
DnsClient extends AbstractDnsClient { public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup) { if (!dnsServerLookup.isAvailable()) { LOGGER.fine("Not adding " + dnsServerLookup.getName() + " as it is not available."); return; } synchronized (LOOKUP_MECHANISMS) { ArrayList<DnsServerLookupMechanism> tempList = new ArrayList<>(LOOKUP_MECHANISMS.size() + 1); tempList.addAll(LOOKUP_MECHANISMS); tempList.add(dnsServerLookup); Collections.sort(tempList); LOOKUP_MECHANISMS.clear(); LOOKUP_MECHANISMS.addAll(tempList); } } DnsClient();  DnsClient(DnsCache dnsCache); @Override DnsQueryResult query(DnsMessage.Builder queryBuilder); static List<String> findDNS(); static List<InetAddress> findDnsAddresses(); static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup); static boolean removeDNSServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup); static boolean addBlacklistedDnsServer(String dnsServer); static boolean removeBlacklistedDnsServer(String dnsServer); boolean isAskForDnssec(); void setAskForDnssec(boolean askForDnssec); boolean isDisableResultFilter(); void setDisableResultFilter(boolean disableResultFilter); boolean isUseHardcodedDnsServersEnabled(); void setUseHardcodedDnsServers(boolean useHardcodedDnsServers); InetAddress getRandomHardcodedIpv4DnsServer(); InetAddress getRandomHarcodedIpv6DnsServer(); }
DnsClient extends AbstractDnsClient { public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup) { if (!dnsServerLookup.isAvailable()) { LOGGER.fine("Not adding " + dnsServerLookup.getName() + " as it is not available."); return; } synchronized (LOOKUP_MECHANISMS) { ArrayList<DnsServerLookupMechanism> tempList = new ArrayList<>(LOOKUP_MECHANISMS.size() + 1); tempList.addAll(LOOKUP_MECHANISMS); tempList.add(dnsServerLookup); Collections.sort(tempList); LOOKUP_MECHANISMS.clear(); LOOKUP_MECHANISMS.addAll(tempList); } } DnsClient();  DnsClient(DnsCache dnsCache); @Override DnsQueryResult query(DnsMessage.Builder queryBuilder); static List<String> findDNS(); static List<InetAddress> findDnsAddresses(); static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup); static boolean removeDNSServerLookupMechanism(DnsServerLookupMechanism dnsServerLookup); static boolean addBlacklistedDnsServer(String dnsServer); static boolean removeBlacklistedDnsServer(String dnsServer); boolean isAskForDnssec(); void setAskForDnssec(boolean askForDnssec); boolean isDisableResultFilter(); void setDisableResultFilter(boolean disableResultFilter); boolean isUseHardcodedDnsServersEnabled(); void setUseHardcodedDnsServers(boolean useHardcodedDnsServers); InetAddress getRandomHardcodedIpv4DnsServer(); InetAddress getRandomHarcodedIpv6DnsServer();  }