lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [38/47] lucenenet git commit: Refactored TestFramework.Util.VirtualMethod and Core.Util.TestVirtualMethod to avoid having to deal with subclasses of test classes (that mess up test context).
Date Tue, 11 Oct 2016 18:35:23 GMT
Refactored TestFramework.Util.VirtualMethod and Core.Util.TestVirtualMethod to avoid having
to deal with subclasses of test classes (that mess up test context).


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/70ae1962
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/70ae1962
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/70ae1962

Branch: refs/heads/master
Commit: 70ae1962578d92b50f5ec0592cfaab5afd028be1
Parents: 2de5494
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Oct 11 03:09:36 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Wed Oct 12 01:10:56 2016 +0700

----------------------------------------------------------------------
 .../Search/AssertingBulkScorer.cs               |  4 +-
 .../Util/VirtualMethod.cs                       |  6 ++-
 .../core/Util/TestVirtualMethod.cs              | 45 ++++++++++++--------
 3 files changed, 34 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/70ae1962/src/Lucene.Net.TestFramework/Search/AssertingBulkScorer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Search/AssertingBulkScorer.cs b/src/Lucene.Net.TestFramework/Search/AssertingBulkScorer.cs
index 3d83eed..ea67747 100644
--- a/src/Lucene.Net.TestFramework/Search/AssertingBulkScorer.cs
+++ b/src/Lucene.Net.TestFramework/Search/AssertingBulkScorer.cs
@@ -28,8 +28,8 @@ namespace Lucene.Net.Search
     /// Wraps a Scorer with additional checks </summary>
     public class AssertingBulkScorer : BulkScorer
     {
-        private static readonly VirtualMethod<BulkScorer> SCORE_COLLECTOR = new VirtualMethod<BulkScorer>(typeof(BulkScorer),
"Score", typeof(Collector));
-        private static readonly VirtualMethod<BulkScorer> SCORE_COLLECTOR_RANGE = new
VirtualMethod<BulkScorer>(typeof(BulkScorer), "Score", typeof(Collector), typeof(int));
+        private static readonly VirtualMethod SCORE_COLLECTOR = new VirtualMethod(typeof(BulkScorer),
"Score", typeof(Collector));
+        private static readonly VirtualMethod SCORE_COLLECTOR_RANGE = new VirtualMethod(typeof(BulkScorer),
"Score", typeof(Collector), typeof(int));
 
         public static BulkScorer Wrap(Random random, BulkScorer other)
         {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/70ae1962/src/Lucene.Net.TestFramework/Util/VirtualMethod.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/VirtualMethod.cs b/src/Lucene.Net.TestFramework/Util/VirtualMethod.cs
index 7cc661b..716a867 100644
--- a/src/Lucene.Net.TestFramework/Util/VirtualMethod.cs
+++ b/src/Lucene.Net.TestFramework/Util/VirtualMethod.cs
@@ -56,7 +56,9 @@ namespace Lucene.Net.Util
     ///
     /// @lucene.internal
     /// </summary>
-    public sealed class VirtualMethod<C>
+    // LUCENENET NOTE: Pointless to make this class generic, since the generic type is never
used (the Type class in .NET
+    // is not generic).
+    public sealed class VirtualMethod
     {
         private static readonly ISet<MethodInfo> SingletonSet = new ConcurrentHashSet<MethodInfo>(new
HashSet<MethodInfo>());
 
@@ -156,7 +158,7 @@ namespace Lucene.Net.Util
         ///  <li>&lt; 1, iff {@code m2} is overridden in a subclass of the class
overriding/declaring {@code m1}
         ///  <li>0, iff both methods are overridden in the same class (or are not overridden
at all)
         /// </ul> </returns>
-        public static int compareImplementationDistance<C>(Type clazz, VirtualMethod<C>
m1, VirtualMethod<C> m2)
+        public static int CompareImplementationDistance(Type clazz, VirtualMethod m1, VirtualMethod
m2)
         {
             return Convert.ToInt32(m1.GetImplementationDistance(clazz)).CompareTo(m2.GetImplementationDistance(clazz));
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/70ae1962/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs b/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
index 14488af..30c8b00 100644
--- a/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
@@ -23,24 +23,33 @@ namespace Lucene.Net.Util
     [TestFixture]
     public class TestVirtualMethod : LuceneTestCase
     {
-        private static readonly VirtualMethod<TestVirtualMethod> PublicTestMethod;
-        private static readonly VirtualMethod<TestVirtualMethod> ProtectedTestMethod;
+        private static readonly VirtualMethod PublicTestMethod;
+        private static readonly VirtualMethod ProtectedTestMethod;
 
         static TestVirtualMethod()
         {
-            PublicTestMethod = new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod),
"PublicTest", typeof(string));
-            ProtectedTestMethod = new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod),
"ProtectedTest", typeof(int));
+            PublicTestMethod = new VirtualMethod(typeof(BaseTestVirtualMethod), "PublicTest",
typeof(string));
+            ProtectedTestMethod = new VirtualMethod(typeof(BaseTestVirtualMethod), "ProtectedTest",
typeof(int));
         }
 
-        public virtual void PublicTest(string test)
+        /// <summary>
+        /// LUCENENET specific class used here because inheriting test classes messes up
the context
+        /// that the tests are run in. So, we substitute a class that has no tests.
+        /// </summary>
+        public class BaseTestVirtualMethod
         {
-        }
 
-        protected virtual void ProtectedTest(int test)
-        {
+            public virtual void PublicTest(string test)
+            {
+            }
+
+            protected virtual void ProtectedTest(int test)
+            {
+            }
+
         }
 
-        internal class TestClass1 : TestVirtualMethod
+        internal class TestClass1 : BaseTestVirtualMethod
         {
             public override void PublicTest(string test)
             {
@@ -65,7 +74,7 @@ namespace Lucene.Net.Util
             }
         }
 
-        internal class TestClass4 : TestVirtualMethod
+        internal class TestClass4 : BaseTestVirtualMethod
         {
         }
 
@@ -76,22 +85,24 @@ namespace Lucene.Net.Util
         [Test]
         public virtual void TestGeneral()
         {
-            Assert.AreEqual(0, PublicTestMethod.GetImplementationDistance(this.GetType()));
+            // LUCENENET: Substituted BaseTestVirtualMethod for this class, but the logic
is the same.
+            Assert.AreEqual(0, PublicTestMethod.GetImplementationDistance(typeof(BaseTestVirtualMethod)));
             Assert.AreEqual(1, PublicTestMethod.GetImplementationDistance(typeof(TestClass1)));
             Assert.AreEqual(1, PublicTestMethod.GetImplementationDistance(typeof(TestClass2)));
             Assert.AreEqual(3, PublicTestMethod.GetImplementationDistance(typeof(TestClass3)));
             Assert.IsFalse(PublicTestMethod.IsOverriddenAsOf(typeof(TestClass4)));
             Assert.IsFalse(PublicTestMethod.IsOverriddenAsOf(typeof(TestClass5)));
 
-            Assert.AreEqual(0, ProtectedTestMethod.GetImplementationDistance(this.GetType()));
+            // LUCENENET: Substituted BaseTestVirtualMethod for this class, but the logic
is the same.
+            Assert.AreEqual(0, ProtectedTestMethod.GetImplementationDistance(typeof(BaseTestVirtualMethod)));
             Assert.AreEqual(1, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass1)));
             Assert.AreEqual(2, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass2)));
             Assert.AreEqual(2, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass3)));
             Assert.IsFalse(ProtectedTestMethod.IsOverriddenAsOf(typeof(TestClass4)));
             Assert.IsFalse(ProtectedTestMethod.IsOverriddenAsOf(typeof(TestClass5)));
 
-            Assert.IsTrue(VirtualMethod<TestVirtualMethod>.compareImplementationDistance(typeof(TestClass3),
PublicTestMethod, ProtectedTestMethod) > 0);
-            Assert.AreEqual(0, VirtualMethod<TestVirtualMethod>.compareImplementationDistance(typeof(TestClass5),
PublicTestMethod, ProtectedTestMethod));
+            Assert.IsTrue(VirtualMethod.CompareImplementationDistance(typeof(TestClass3),
PublicTestMethod, ProtectedTestMethod) > 0);
+            Assert.AreEqual(0, VirtualMethod.CompareImplementationDistance(typeof(TestClass5),
PublicTestMethod, ProtectedTestMethod));
         }
 
         [Test]
@@ -110,7 +121,7 @@ namespace Lucene.Net.Util
 
             try
             {
-                new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "bogus");
+                new VirtualMethod(typeof(BaseTestVirtualMethod), "bogus");
                 Assert.Fail("Method bogus() does not exist, so IAE should be thrown");
             }
             catch (System.ArgumentException arg)
@@ -120,7 +131,7 @@ namespace Lucene.Net.Util
 
             try
             {
-                new VirtualMethod<TestClass2>(typeof(TestClass2), "PublicTest", typeof(string));
+                new VirtualMethod(typeof(TestClass2), "PublicTest", typeof(string));
             }
             catch (System.ArgumentException arg)
             {
@@ -130,7 +141,7 @@ namespace Lucene.Net.Util
             try
             {
                 // try to create a second instance of the same baseClass / method combination
-                new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "PublicTest",
typeof(string));
+                new VirtualMethod(typeof(BaseTestVirtualMethod), "PublicTest", typeof(string));
                 Assert.Fail("Violating singleton status succeeded");
             }
             catch (System.ArgumentException arg)


Mime
View raw message