All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jodah.concurrentunit.testng.ConcurrentTestCase Maven / Gradle / Ivy

The newest version!
package org.jodah.concurrentunit.testng;

import org.jodah.concurrentunit.AbstractConcurrentTestCase;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;

/**
 * Concurrent TestNG test case.
 * 
 * 

* Call {@link #sleep(long)}, {@link #sleep(long, int)}, {@link #threadWait(long)} or * {@link #threadWait(long, int)} from the main unit test thread to wait for some other thread to * perform assertions. These operations will block until {@link #resume()} is called, the operation * times out, or a threadAssert call fails. * *

* The threadAssert methods can be used from any thread to perform concurrent assertions. Assertion * failures will result in the main thread being interrupted and the failure thrown. * *

* Usage: * *

 * @Test
 * public void assertAndResume() throws Throwable {
 *   new Thread(new Runnable() {
 *     public void run() {
 *       threadAssertTrue(true);
 *       resume();
 *     }
 *   }).start();
 *   
 *   sleep(500);
 * }
 * 
* * @author Jonathan Halterman */ public abstract class ConcurrentTestCase extends AbstractConcurrentTestCase { @BeforeMethod public void initContext() { waitCount = null; failure = null; } @Override protected void assertEquals(Object actual, Object expected) { Assert.assertEquals(actual, expected); } @Override protected void assertFalse(boolean condition) { Assert.assertFalse(condition); } @Override protected void assertNotNull(Object o) { Assert.assertNotNull(o); } @Override protected void assertNull(Object o) { Assert.assertNull(o); } @Override protected void assertTrue(boolean condition) { Assert.assertTrue(condition); } @Override protected void fail(String message) { Assert.fail(message); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy