### Question:
NetUtils { public static DNSToSwitchMapping getDNSResolver(Class<? extends DNSToSwitchMapping> resolverCls, String hostRegionOverrides) { Constructor<? extends DNSToSwitchMapping> constructor; Object[] parameters; try { constructor = resolverCls.getDeclaredConstructor(String.class); parameters = new Object[] { hostRegionOverrides }; } catch (NoSuchMethodException nsme) { try { constructor = resolverCls.getDeclaredConstructor(); parameters = new Object[0]; } catch (NoSuchMethodException nsme1) { throw new RuntimeException("Unable to find constructor for dns resolver " + resolverCls, nsme1); } } constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (InstantiationException ie) { throw new RuntimeException("Unable to instantiate dns resolver " + resolverCls, ie); } catch (IllegalAccessException iae) { throw new RuntimeException("Illegal access to dns resolver " + resolverCls, iae); } catch (InvocationTargetException ite) { throw new RuntimeException("Unable to construct dns resolver " + resolverCls, ite); } }  static DNSToSwitchMapping getDNSResolver(Class<? extends DNSToSwitchMapping> resolverCls,
                                                    String hostRegionOverrides);  }### Answer:
@Test(timeout = 20000) public void testGetDNSResolverWithOverrides() throws Exception { DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(DNSResolverForRacks.class, ""); assertEquals("Should succeed to load " + DNSResolverForRacks.class, dnsResolver.getClass(), DNSResolverForRacks.class); }
@Test(timeout = 20000) public void testGetDNSResolverWithDefaultConstructor() throws Exception { DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(DNSResolverWithDefaultConstructor.class, ""); assertEquals("Should succeed to load " + DNSResolverWithDefaultConstructor.class, dnsResolver.getClass(), DNSResolverWithDefaultConstructor.class); }
@Test(timeout = 20000, expected = RuntimeException.class) public void testGetDNSResolverWithUnknownConstructor() throws Exception { NetUtils.getDNSResolver(DNSResolverWithUnknownConstructor.class, ""); }