lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r922887 - /lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
Date Sun, 14 Mar 2010 16:31:07 GMT
Author: uschindler
Date: Sun Mar 14 16:31:07 2010
New Revision: 922887

URL: http://svn.apache.org/viewvc?rev=922887&view=rev
Log:
LUCENE-2037: Added a check for now, that tests in LuceneTestCaseJ4, that all JUnit4 tests
have @Test added to all methods with name.startsWith("test"). This helps us during converting
tests to JUnit4, as i found lots of tests that simply forgot to add @Test and were never ran.

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java?rev=922887&r1=922886&r2=922887&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java Sun Mar 14 16:31:07
2010
@@ -25,6 +25,7 @@ import org.apache.lucene.util.FieldCache
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
+import org.junit.Test;
 import org.junit.rules.TestWatchman;
 import org.junit.runners.model.FrameworkMethod;
 
@@ -36,7 +37,10 @@ import java.util.Iterator;
 import java.util.Random;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
 import java.util.Collections;
+import java.lang.reflect.Method;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -113,6 +117,11 @@ public class LuceneTestCaseJ4 {
   }
   private List<UncaughtExceptionEntry> uncaughtExceptions = Collections.synchronizedList(new
ArrayList<UncaughtExceptionEntry>());
   
+  // checks if class correctly annotated
+  private static final Object PLACEHOLDER = new Object();
+  private static final Map<Class<? extends LuceneTestCaseJ4>,Object> checkedClasses
=
+    Collections.synchronizedMap(new WeakHashMap<Class<? extends LuceneTestCaseJ4>,Object>());
+  
   // This is how we get control when errors occur.
   // Think of this as start/end/success/failed
   // events.
@@ -127,7 +136,18 @@ public class LuceneTestCaseJ4 {
 
     @Override
     public void starting(FrameworkMethod method) {
+      // set current method name for logging
       LuceneTestCaseJ4.this.name = method.getName();
+      // check if the current test's class annotated all test* methods with @Test
+      final Class<? extends LuceneTestCaseJ4> clazz = LuceneTestCaseJ4.this.getClass();
+      if (!checkedClasses.containsKey(clazz)) {
+        checkedClasses.put(clazz, PLACEHOLDER);
+        for (Method m : clazz.getMethods()) {
+          if (m.getName().startsWith("test") && m.getAnnotation(Test.class) == null)
{
+            fail("In class '" + clazz.getName() + "' the method '" + m.getName() + "' is
not annotated with @Test.");
+          }
+        }
+      }
       super.starting(method);
     }
     



Mime
View raw message