mirror of https://github.com/apache/lucene.git
factor out some more helper classes from LuceneTestCase into separate .java files
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1161972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f04bb785bb
commit
cb0b8c02e0
|
@ -501,7 +501,7 @@ public abstract class LuceneTestCase extends Assert {
|
|||
// 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 extends Assert {
|
|||
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 extends Assert {
|
|||
}
|
||||
|
||||
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 extends Assert {
|
|||
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>";
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue