Skip to content

Commit

Permalink
Added probe to check to see if docnap has finished before checking wh…
Browse files Browse the repository at this point in the history
…ether there were any errors.
  • Loading branch information
jenny99r committed Mar 31, 2010
1 parent e3f8819 commit 236fb6a
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.hamcrest.Description;
import org.jdesktop.application.Application;
import org.netmelody.docnap.swingclient.DocnapMain;
import org.netmelody.docnap.swingclient.testsupport.driver.DocnapApplicationDriver;
import org.netmelody.docnap.swingclient.testsupport.driver.DocnapDocumentDetailsFrameDriver;
import org.netmelody.docnap.swingclient.testsupport.driver.DocnapStoreChooserDriver;

import com.objogate.wl.Probe;
import com.objogate.wl.UnsynchronizedProber;

public final class DocnapApplicationRunner {

private DocnapApplicationDriver applicationDriver;
Expand Down Expand Up @@ -58,9 +62,7 @@ public void close() throws SecurityException {}
public void flush() {}
@Override
public void publish(LogRecord record) {
System.out.println("hello");
if (record.getLevel().equals(Level.SEVERE)) {
System.out.println("bad");
DocnapApplicationRunner.this.hasErrored = true;
}
}
Expand Down Expand Up @@ -125,9 +127,55 @@ public void showsMainFrameWithTitleContaining(String myHomeFolderPath) {
public DocnapDocumentDetailsFrameDriver showsDocumentDetailsForADocumentTitled(String title) {
return new DocnapDocumentDetailsFrameDriver(applicationDriver, title);
}

private boolean hasFinished(ThreadGroup group)
{
int numThreads = group.activeCount();
Thread[] threads = new Thread[numThreads*2];
numThreads = group.enumerate(threads, false);

for (int i=0; i<numThreads; i++) {
// Get thread
Thread thread = threads[i];
if (thread.getName().startsWith("AWT-EventQueue")) {
if (Thread.State.WAITING == thread.getState()) {
return true;
}
else {
return false;
}
}
}

return true;
}

public void hasClosed() {
System.out.println("hasErrored " + hasErrored);
UnsynchronizedProber checkFinished = new UnsynchronizedProber();

checkFinished.check(new Probe() {

@Override
public void describeTo(Description description) {
}

@Override
public void probe() {
}

@Override
public boolean isSatisfied() {
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
return hasFinished(threadGroup);

}

@Override
public void describeFailureTo(Description description) {

}
});

assertThat(hasErrored, is(false));
}

Expand Down

0 comments on commit 236fb6a

Please sign in to comment.