Apache Solr open-source search software
Wait for the thread to fail in beforeclass.
Dawid Weiss1557e02f4740
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.javaindex 6d6234e51e6..72b523a316b 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java@@ -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 {@Testpublic 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