- Timestamp:
- 07/02/13 16:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r88 r90 1 1 package com.framsticks.test; 2 3 import java.util.LinkedList; 4 import java.util.List; 2 5 3 6 import org.apache.log4j.Logger; … … 5 8 import org.testng.annotations.*; 6 9 10 import com.framsticks.util.dispatching.Dispatcher; 11 import com.framsticks.util.dispatching.RunAt; 12 7 13 public class TestConfiguration { 8 14 9 private static final Logger log = 10 Logger.getLogger(TestConfiguration.class); 15 private static final Logger log = Logger.getLogger(TestConfiguration.class); 11 16 12 17 @BeforeClass … … 16 21 } 17 22 23 private final List<AsyncAssert<?>> asyncAssertions = new LinkedList<AsyncAssert<?>>(); 24 25 public class AsyncAssert<C> extends RunAt<C> { 26 final RunAt<? extends C> runnable; 27 boolean done = false; 28 AssertionError assertion; 29 30 /** 31 * @param runnable 32 */ 33 public AsyncAssert(RunAt<? extends C> runnable) { 34 this.runnable = runnable; 35 } 36 37 @Override 38 public void run() { 39 try { 40 runnable.run(); 41 } catch (AssertionError e) { 42 assertion = e; 43 } 44 synchronized (this) { 45 done = true; 46 this.notifyAll(); 47 } 48 } 49 } 50 51 public <C> void assertDispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) { 52 AsyncAssert<C> assertion = new AsyncAssert<C>(runnable); 53 synchronized (asyncAssertions) { 54 asyncAssertions.add(assertion); 55 } 56 dispatcher.dispatch(assertion); 57 } 58 59 @BeforeMethod 60 public void clearAsyncAsserts() { 61 synchronized (asyncAssertions) { 62 asyncAssertions.clear(); 63 } 64 } 65 66 @AfterMethod(timeOut = 5000) 67 public void waitForAsyncAsserts() { 68 while (true) { 69 AsyncAssert<?> assertion; 70 synchronized (asyncAssertions) { 71 if (asyncAssertions.isEmpty()) { 72 return; 73 } 74 assertion = asyncAssertions.get(0); 75 asyncAssertions.remove(0); 76 } 77 synchronized (assertion) { 78 while (!assertion.done) { 79 try { 80 assertion.wait(); 81 } catch (InterruptedException ignored) { 82 } 83 } 84 if (assertion.assertion != null) { 85 throw assertion.assertion; 86 } 87 } 88 } 89 } 18 90 }
Note: See TracChangeset
for help on using the changeset viewer.