Skip to content

Commit

Permalink
Our own cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
David Saff committed Nov 17, 2009
1 parent c8a7052 commit f8ee06b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/junit/runner/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class Result {
private AtomicInteger fCount = new AtomicInteger();
private AtomicInteger fIgnoreCount= new AtomicInteger();
private final List<Failure> fFailures= Collections.synchronizedList( new ArrayList<Failure>());
private volatile long fRunTime= 0;
private volatile long fStartTime;
private long fRunTime= 0;
private long fStartTime;

/**
* @return the number of tests run
Expand Down
35 changes: 15 additions & 20 deletions src/main/java/org/junit/runner/notification/RunNotifier.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.junit.runner.notification;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand All @@ -16,37 +17,33 @@
* to a separate class since they should only be called once per run.
*/
public class RunNotifier {
private final Object fListenersLock = new Object();
private final List<RunListener> fListeners= new ArrayList<RunListener>();
private final List<RunListener> fListeners=
Collections.synchronizedList(new ArrayList<RunListener>());
private boolean fPleaseStop= false;

/** Internal use only
*/
public void addListener(RunListener listener) {
synchronized ( fListenersLock) {
fListeners.add(listener);
}
fListeners.add(listener);
}

/** Internal use only
*/
public void removeListener(RunListener listener) {
synchronized ( fListenersLock) {
fListeners.remove(listener);
}
fListeners.remove(listener);
}

private abstract class SafeNotifier {
void run() {
synchronized ( fListenersLock) {
for (Iterator<RunListener> all= fListeners.iterator(); all.hasNext();)
try {
notifyListener(all.next());
} catch (Exception e) {
all.remove(); // Remove the offending listener first to avoid an infinite loop
fireTestFailure(new Failure(Description.TEST_MECHANISM, e));
}
}
synchronized (fListeners) {
for (Iterator<RunListener> all= fListeners.iterator(); all.hasNext();)
try {
notifyListener(all.next());
} catch (Exception e) {
all.remove(); // Remove the offending listener first to avoid an infinite loop
fireTestFailure(new Failure(Description.TEST_MECHANISM, e));
}
}
}

abstract protected void notifyListener(RunListener each) throws Exception;
Expand Down Expand Up @@ -164,8 +161,6 @@ public void pleaseStop() {
* Internal use only. The Result's listener must be first.
*/
public void addFirstListener(RunListener listener) {
synchronized ( fListenersLock) {
fListeners.add(0, listener);
}
fListeners.add(0, listener);
}
}

0 comments on commit f8ee06b

Please sign in to comment.