mirror of https://github.com/apache/lucene.git
Wait for the thread to fail in beforeclass.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1298760 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ed93626ffc
commit
1557e02f47
|
@ -1,32 +1,40 @@
|
|||
package org.apache.lucene.util.junitcompat;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.JUnitCore;
|
||||
import org.junit.runner.Result;
|
||||
import org.junit.runner.notification.Failure;
|
||||
|
||||
public class TestExceptionInBeforeClassHooks extends WithNestedTests {
|
||||
public TestExceptionInBeforeClassHooks() {
|
||||
super(true);
|
||||
super(false);
|
||||
}
|
||||
|
||||
public static class Nested1 extends WithNestedTests.AbstractNestedTest {
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
new Thread() {
|
||||
public static void beforeClass() throws Exception {
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
throw new RuntimeException("foobar");
|
||||
}
|
||||
}.start();
|
||||
};
|
||||
t.start();
|
||||
t.join();
|
||||
}
|
||||
|
||||
public void test() {}
|
||||
}
|
||||
|
||||
public static class Nested2 extends WithNestedTests.AbstractNestedTest {
|
||||
public static class Nested2 extends LuceneTestCase {
|
||||
public void test1() throws Exception {
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
|
@ -46,6 +54,16 @@ public class TestExceptionInBeforeClassHooks extends WithNestedTests {
|
|||
t.start();
|
||||
t.join();
|
||||
}
|
||||
|
||||
public void test3() throws Exception {
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
throw new RuntimeException("foobar3");
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Nested3 extends WithNestedTests.AbstractNestedTest {
|
||||
|
@ -75,14 +93,20 @@ public class TestExceptionInBeforeClassHooks extends WithNestedTests {
|
|||
@Test
|
||||
public void testExceptionWithinTestFailsTheTest() {
|
||||
Result runClasses = JUnitCore.runClasses(Nested2.class);
|
||||
Assert.assertEquals(2, runClasses.getFailureCount());
|
||||
Assert.assertEquals(2, runClasses.getRunCount());
|
||||
Assert.assertEquals(3, runClasses.getFailureCount());
|
||||
Assert.assertEquals(3, runClasses.getRunCount());
|
||||
|
||||
String m1 = runClasses.getFailures().get(0).getTrace();
|
||||
String m2 = runClasses.getFailures().get(1).getTrace();
|
||||
Assert.assertTrue(
|
||||
(m1.contains("foobar1") && m2.contains("foobar2")) ||
|
||||
(m1.contains("foobar2") && m2.contains("foobar1")));
|
||||
ArrayList<String> foobars = new ArrayList<String>();
|
||||
for (Failure f : runClasses.getFailures()) {
|
||||
Matcher m = Pattern.compile("foobar[0-9]+").matcher(f.getTrace());
|
||||
while (m.find()) {
|
||||
foobars.add(m.group());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(foobars);
|
||||
Assert.assertEquals("[foobar1, foobar2, foobar3]",
|
||||
Arrays.toString(foobars.toArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue