/// <summary>Spy on the Java DNS infrastructure.</summary> /// <remarks> /// Spy on the Java DNS infrastructure. /// This likely only works on Sun-derived JDKs, but uses JUnit's /// Assume functionality so that any tests using it are skipped on /// incompatible JDKs. /// </remarks> private NameService SpyOnNameService() { try { FieldInfo f = Sharpen.Runtime.GetDeclaredField(typeof(IPAddress), "nameServices"); Assume.AssumeNotNull(f); IList <NameService> nsList = (IList <NameService>)f.GetValue(null); NameService ns = nsList[0]; Log log = LogFactory.GetLog("NameServiceSpy"); ns = Org.Mockito.Mockito.Mock <NameService>(new GenericTestUtils.DelegateAnswer(log , ns)); nsList.Set(0, ns); return(ns); } catch (Exception t) { Log.Info("Unable to spy on DNS. Skipping test.", t); // In case the JDK we're testing on doesn't work like Sun's, just // skip the test. Assume.AssumeNoException(t); throw new RuntimeException(t); } }