Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-2037: Add support for LuceneTestCase.getName() for backwards compatibility when reporting failed tests. Also removed The InterceptTestCaseEvents class and added as anonymous class (simplified, no reflection)

Uwe Schindler04558dada33f
diff --git a/src/test/org/apache/lucene/util/InterceptTestCaseEvents.java b/src/test/org/apache/lucene/util/InterceptTestCaseEvents.java
deleted file mode 100644
index 1ebe1fd5547..00000000000
--- a/src/test/org/apache/lucene/util/InterceptTestCaseEvents.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.apache.lucene.util;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-import org.junit.rules.TestWatchman;
-import org.junit.runners.model.FrameworkMethod;
-
-import java.lang.reflect.Method;
-
-
-public final class InterceptTestCaseEvents extends TestWatchman {
- private Object obj;
-
- public InterceptTestCaseEvents(Object obj) {
- this.obj = obj;
- }
-
- @Override
- public void failed(Throwable e, FrameworkMethod method) {
- try {
- Method reporter = method.getMethod().getDeclaringClass().getMethod("reportAdditionalFailureInfo",(Class<?>[]) null);
- reporter.invoke(obj, (Object[])null);
- } catch (Exception e1) {
- System.err.println("InterceptTestCaseEvents.failed(). Cannot invoke reportAdditionalFailureInfo() method in" +
- " consuming class, is it declared and public?");
- }
- super.failed(e, method);
- }
-
- @Override
- public void finished(FrameworkMethod method) {
- super.finished(method);
- }
-
- @Override
- public void starting(FrameworkMethod method) {
- super.starting(method);
- }
-
- @Override
- public void succeeded(FrameworkMethod method) {
- super.succeeded(method);
- }
-}
diff --git a/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
index 23a5b0d380b..f79bee5b9da 100644
--- a/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
+++ b/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
@@ -25,6 +25,8 @@ import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
+import org.junit.rules.TestWatchman;
+import org.junit.runners.model.FrameworkMethod;
import java.io.PrintStream;
import java.util.Arrays;
@@ -98,14 +100,21 @@ public class LuceneTestCaseJ4 {
// Think of this as start/end/success/failed
// events.
@Rule
- public InterceptTestCaseEvents intercept = new InterceptTestCaseEvents(this);
+ public final TestWatchman intercept = new TestWatchman() {
- public LuceneTestCaseJ4() {
- }
+ @Override
+ public void failed(Throwable e, FrameworkMethod method) {
+ reportAdditionalFailureInfo();
+ super.failed(e, method);
+ }
- public LuceneTestCaseJ4(String name) {
- this.name = name;
- }
+ @Override
+ public void starting(FrameworkMethod method) {
+ LuceneTestCaseJ4.this.name = method.getName();
+ super.starting(method);
+ }
+
+ };
@Before
public void setUp() throws Exception {
@@ -291,6 +300,6 @@ public class LuceneTestCaseJ4 {
// static members
private static final Random seedRnd = new Random();
- private String name = "";
+ private String name = "<unknown>";
}