### Question:
DNSUtil { public static boolean isNameCoveredByPattern( String name, String pattern ) { if ( name == null || name.isEmpty() || pattern == null || pattern.isEmpty() ) { throw new IllegalArgumentException( "Arguments cannot be null or empty." ); } final String needle = name.toLowerCase(); final String hayStack = pattern.toLowerCase(); if ( needle.equals( hayStack )) { return true; } if ( hayStack.startsWith( "*." ) ) { return needle.endsWith( hayStack.substring( 2 ) ); } return false; }  static List<HostAddress> resolveXMPPDomain(String domain, int defaultPort); static Map<String, HostAddress> getDnsOverride(); static void setDnsOverride(Map<String, HostAddress> dnsOverride); static List<WeightedHostAddress> srvLookup(String service, String proto, String name); static boolean isNameCoveredByPattern( String name, String pattern ); static List<WeightedHostAddress> prioritize(WeightedHostAddress[] records);  }### Answer:
@Test public void testNameCoverageExactMatch() throws Exception { final String name = "xmpp.example.org"; final String pattern = name; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertTrue( result ); }
@Test public void testNameCoverageUnequal() throws Exception { final String name = "xmpp.example.org"; final String pattern = "something.completely.different"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertFalse( result ); }
@Test public void testNameCoverageSubdomainNoWildcard() throws Exception { final String name = "xmpp.example.org"; final String pattern = "example.org"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertFalse( result ); }
@Test public void testNameCoveragePartialMatchButNoSubdomain() throws Exception { final String name = "xmppexample.org"; final String pattern = "example.org"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertFalse( result ); }
@Test public void testNameCoverageSubdomainWithWildcard() throws Exception { final String name = "xmpp.example.org"; final String pattern = "*.example.org"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertTrue( result ); }
@Test public void testNameCoverageSubSubdomainWithWildcard() throws Exception { final String name = "deeper.xmpp.example.org"; final String pattern = "*.example.org"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertTrue( result ); }
@Test public void testNameCoverageSubdomainWithWildcardOfSameDomain() throws Exception { final String name = "xmpp.example.org"; final String pattern = "*.xmpp.example.org"; final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); Assert.assertTrue( result ); }