You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/08/26 04:54:03 UTC
svn commit: r1161972 - in
/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util:
LuceneTestCase.java SmartRandom.java _TestIgnoredException.java
Author: rmuir
Date: Fri Aug 26 02:54:02 2011
New Revision: 1161972
URL: http://svn.apache.org/viewvc?rev=1161972&view=rev
Log:
factor out some more helper classes from LuceneTestCase into separate .java files
Added:
lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/SmartRandom.java (with props)
lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestIgnoredException.java (with props)
Modified:
lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
Modified: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1161972&r1=1161971&r2=1161972&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java Fri Aug 26 02:54:02 2011
@@ -501,7 +501,7 @@ public abstract class LuceneTestCase ext
// org.junit.internal.AssumptionViolatedException in older releases
// org.junit.Assume.AssumptionViolatedException in recent ones
if (e.getClass().getName().endsWith("AssumptionViolatedException")) {
- if (e.getCause() instanceof TestIgnoredException)
+ if (e.getCause() instanceof _TestIgnoredException)
e = e.getCause();
System.err.print("NOTE: Assume failed in '" + method.getName() + "' (ignored):");
if (VERBOSE) {
@@ -798,39 +798,8 @@ public abstract class LuceneTestCase ext
assertEquals(message, Float.valueOf(expected), Float.valueOf(actual));
}
- // Replacement for Assume jUnit class, so we can add a message with explanation:
-
- private static final class TestIgnoredException extends RuntimeException {
- TestIgnoredException(String msg) {
- super(msg);
- }
-
- TestIgnoredException(String msg, Throwable t) {
- super(msg, t);
- }
-
- @Override
- public String getMessage() {
- StringBuilder sb = new StringBuilder(super.getMessage());
- if (getCause() != null)
- sb.append(" - ").append(getCause());
- return sb.toString();
- }
-
- // only this one is called by our code, exception is not used outside this class:
- @Override
- public void printStackTrace(PrintStream s) {
- if (getCause() != null) {
- s.println(super.toString() + " - Caused by:");
- getCause().printStackTrace(s);
- } else {
- super.printStackTrace(s);
- }
- }
- }
-
public static void assumeTrue(String msg, boolean b) {
- Assume.assumeNoException(b ? null : new TestIgnoredException(msg));
+ Assume.assumeNoException(b ? null : new _TestIgnoredException(msg));
}
public static void assumeFalse(String msg, boolean b) {
@@ -838,7 +807,7 @@ public abstract class LuceneTestCase ext
}
public static void assumeNoException(String msg, Exception e) {
- Assume.assumeNoException(e == null ? null : new TestIgnoredException(msg, e));
+ Assume.assumeNoException(e == null ? null : new _TestIgnoredException(msg, e));
}
public static <T> Set<T> asSet(T... args) {
@@ -1360,25 +1329,6 @@ public abstract class LuceneTestCase ext
static final Random seedRand = new Random();
protected static final SmartRandom random = new SmartRandom(0);
- public static class SmartRandom extends Random {
- boolean initialized;
-
- SmartRandom(long seed) {
- super(seed);
- }
-
- @Override
- protected int next(int bits) {
- if (!initialized) {
- System.err.println("!!! WARNING: test is using random from static initializer !!!");
- Thread.dumpStack();
- // I wish, but it causes JRE crashes
- // throw new IllegalStateException("you cannot use this random from a static initializer in your test");
- }
- return super.next(bits);
- }
- }
-
private String name = "<unknown>";
/**
Added: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/SmartRandom.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/SmartRandom.java?rev=1161972&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/SmartRandom.java (added)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/SmartRandom.java Fri Aug 26 02:54:02 2011
@@ -0,0 +1,43 @@
+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 java.util.Random;
+
+/**
+ * A random that tracks if its been initialized properly,
+ * and throws an exception if it hasn't.
+ */
+public class SmartRandom extends Random {
+ boolean initialized;
+
+ SmartRandom(long seed) {
+ super(seed);
+ }
+
+ @Override
+ protected int next(int bits) {
+ if (!initialized) {
+ System.err.println("!!! WARNING: test is using random from static initializer !!!");
+ Thread.dumpStack();
+ // I wish, but it causes JRE crashes
+ // throw new IllegalStateException("you cannot use this random from a static initializer in your test");
+ }
+ return super.next(bits);
+ }
+}
Added: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestIgnoredException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestIgnoredException.java?rev=1161972&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestIgnoredException.java (added)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestIgnoredException.java Fri Aug 26 02:54:02 2011
@@ -0,0 +1,51 @@
+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 java.io.PrintStream;
+
+/** Replacement for Assume jUnit class, so we can add a message with explanation */
+final class _TestIgnoredException extends RuntimeException {
+
+ _TestIgnoredException(String msg) {
+ super(msg);
+ }
+
+ _TestIgnoredException(String msg, Throwable t) {
+ super(msg, t);
+ }
+
+ @Override
+ public String getMessage() {
+ StringBuilder sb = new StringBuilder(super.getMessage());
+ if (getCause() != null)
+ sb.append(" - ").append(getCause());
+ return sb.toString();
+ }
+
+ // only this one is called by our code, exception is not used outside this class:
+ @Override
+ public void printStackTrace(PrintStream s) {
+ if (getCause() != null) {
+ s.println(super.toString() + " - Caused by:");
+ getCause().printStackTrace(s);
+ } else {
+ super.printStackTrace(s);
+ }
+ }
+}