Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EventCollector if possible. #936

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/test/java/org/junit/rules/ErrorCollectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.testsupport.EventCollector;

import java.util.concurrent.Callable;

Expand All @@ -20,7 +21,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.junit.rules.EventCollector.*;
import static org.junit.testsupport.EventCollectorMatchers.*;

@RunWith(Parameterized.class)
public class ErrorCollectorTest {
Expand Down
191 changes: 0 additions & 191 deletions src/test/java/org/junit/rules/EventCollector.java

This file was deleted.

9 changes: 5 additions & 4 deletions src/test/java/org/junit/rules/ExpectedExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.junit.rules.ExpectedException.none;
import static org.junit.rules.EventCollector.everyTestRunSuccessful;
import static org.junit.rules.EventCollector.hasSingleAssumptionFailure;
import static org.junit.rules.EventCollector.hasSingleFailure;
import static org.junit.rules.EventCollector.hasSingleFailureWithMessage;
import static org.junit.testsupport.EventCollectorMatchers.everyTestRunSuccessful;
import static org.junit.testsupport.EventCollectorMatchers.hasSingleAssumptionFailure;
import static org.junit.testsupport.EventCollectorMatchers.hasSingleFailure;
import static org.junit.testsupport.EventCollectorMatchers.hasSingleFailureWithMessage;

import java.util.Collection;

Expand All @@ -26,6 +26,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.testsupport.EventCollector;

@RunWith(Parameterized.class)
public class ExpectedExceptionTest {
Expand Down
47 changes: 11 additions & 36 deletions src/test/java/org/junit/runner/FilterOptionIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.junit.runner;

import java.util.HashSet;
import java.util.Set;

import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.experimental.categories.ExcludeCategories;
import org.junit.experimental.categories.IncludeCategories;
import org.junit.runner.notification.RunListener;
import org.junit.tests.TestSystem;
import org.junit.testsupport.EventCollector;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.testsupport.EventCollectorMatchers.hasTestFinished;
import static org.junit.testsupport.EventCollectorMatchers.hasTestStarted;

public class FilterOptionIntegrationTest {
private static final String INCLUDES_DUMMY_CATEGORY_0 = "--filter=" +
Expand All @@ -23,7 +23,7 @@ public class FilterOptionIntegrationTest {
ExcludeCategories.class.getName() + "=" + DummyCategory1.class.getName();

private JUnitCore jUnitCore = new JUnitCore();
private TestListener testListener = new TestListener();
private EventCollector testListener = new EventCollector();

@Before
public void setUp() {
Expand Down Expand Up @@ -111,40 +111,15 @@ private Result runJUnit(final String... args) {
}

private void assertWasRun(Class<?> testClass) {
assertTrue(testClass.getName() + " expected to finish but did not", testListener.wasRun(testClass));
assertThat(testListener, wasRun(testClass));
}

private void assertWasNotRun(Class<?> testClass) {
assertFalse(
testClass.getName() + " expected not to have been started but was",
testListener.wasRun(testClass));
assertThat(testListener, not(wasRun(testClass)));
}

private static class TestListener extends RunListener {
private Set<String> startedTests = new HashSet<String>();
private Set<String> finishedTests = new HashSet<String>();

@Override
public void testFinished(final Description description) {
finishedTests.add(description.getClassName());
}

private boolean testFinished(final Class<?> testClass) {
return finishedTests.contains(testClass.getName());
}

@Override
public void testStarted(final Description description) {
startedTests.add(description.getClassName());
}

private boolean testStarted(final Class<?> testClass) {
return startedTests.contains(testClass.getName());
}

public boolean wasRun(final Class<?> testClass) {
return testStarted(testClass) && testFinished(testClass);
}
private Matcher<EventCollector> wasRun(Class<?> testClass) {
return allOf(hasTestStarted(testClass), hasTestFinished(testClass));
}

public static class DummyTestClass {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/junit/runner/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.rules.EventCollector.hasSingleFailureWithMessage;
import static org.junit.testsupport.EventCollectorMatchers.hasSingleFailureWithMessage;

import org.junit.Test;
import org.junit.rules.EventCollector;
import org.junit.testsupport.EventCollector;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.junit.runner.notification;

import org.junit.Test;
import org.junit.runner.Description;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.testsupport.EventCollectorMatchers.hasNumberOfTestsStarted;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.testsupport.EventCollector;

/**
* Testing RunNotifier in concurrent access.
Expand All @@ -26,21 +27,13 @@
*/
public final class ConcurrentRunNotifierTest {
private static final long TIMEOUT = 3;
private final RunNotifier fNotifier = new RunNotifier();

private static class ConcurrentRunListener extends RunListener {
final AtomicInteger fTestStarted = new AtomicInteger(0);

@Override
public void testStarted(Description description) throws Exception {
fTestStarted.incrementAndGet();
}
}
private final RunNotifier fNotifier = new RunNotifier();

@Test
public void realUsage() throws Exception {
ConcurrentRunListener listener1 = new ConcurrentRunListener();
ConcurrentRunListener listener2 = new ConcurrentRunListener();
EventCollector listener1 = new EventCollector();
EventCollector listener2 = new EventCollector();
fNotifier.addListener(listener1);
fNotifier.addListener(listener2);

Expand All @@ -59,8 +52,8 @@ public void run() {
fNotifier.removeListener(listener1);
fNotifier.removeListener(listener2);

assertThat(listener1.fTestStarted.get(), is(numParallelTests));
assertThat(listener2.fTestStarted.get(), is(numParallelTests));
assertThat(listener1, hasNumberOfTestsStarted(numParallelTests));
assertThat(listener2, hasNumberOfTestsStarted(numParallelTests));
}

private static class ExaminedListener extends RunListener {
Expand Down
Loading