|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| FromAnotherThread.java | 100% | 95.5% | 87.5% | 94.1% |
|
||||||||||||||
| 1 |
package failing;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.jfcunit.JFCTestCase;
|
|
| 4 |
import junit.extensions.jfcunit.JFCTestHelper;
|
|
| 5 |
|
|
| 6 |
/**
|
|
| 7 |
* <p>Title: Test submitting failures.</p>
|
|
| 8 |
* <p>Description: This test case submits failures from
|
|
| 9 |
* another thread.</p>
|
|
| 10 |
* <p>Copyright: Copyright (c) 2002</p>
|
|
| 11 |
* <p>Company: JFCUnit OpenSource Project</p>
|
|
| 12 |
* @author Kevin Wilson
|
|
| 13 |
* @version 1.0
|
|
| 14 |
*/
|
|
| 15 |
public class FromAnotherThread extends JFCTestCase { |
|
| 16 |
|
|
| 17 |
/**
|
|
| 18 |
* Flag to indicate the completion of the background
|
|
| 19 |
* thread.
|
|
| 20 |
*/
|
|
| 21 |
private volatile boolean m_done = false; |
|
| 22 |
|
|
| 23 |
/**
|
|
| 24 |
* Constructor.
|
|
| 25 |
* @param name Name of the test case.
|
|
| 26 |
*/
|
|
| 27 | 3 |
public FromAnotherThread(final String name) {
|
| 28 | 3 |
super(name);
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/**
|
|
| 32 |
* Setup the test case.
|
|
| 33 |
* @throws Exception may be thrown.
|
|
| 34 |
*/
|
|
| 35 | 3 |
public void setUp() throws Exception { |
| 36 | 3 |
super.setUp();
|
| 37 | 3 |
setHelper(new JFCTestHelper());
|
| 38 | 3 |
m_done = false;
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* Test failing from another thread.
|
|
| 43 |
*/
|
|
| 44 | 1 |
public void testFailFromAnotherThread() { |
| 45 | 1 |
Thread th = new Thread(new Runnable() { |
| 46 | 1 |
public void run() { |
| 47 | 1 |
try {
|
| 48 | 1 |
fail("This fails from another thread");
|
| 49 |
} catch (Throwable throwable) {
|
|
| 50 | 1 |
setError(throwable); |
| 51 |
} |
|
| 52 | 1 |
m_done = true;
|
| 53 |
} |
|
| 54 |
}, "Fail from this thread.");
|
|
| 55 | 1 |
th.start(); |
| 56 | 1 |
while (!m_done) {
|
| 57 | 1 |
sleep(25); |
| 58 |
} |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/**
|
|
| 62 |
* Test a Assert from another thread.
|
|
| 63 |
*/
|
|
| 64 | 1 |
public void testAssertFromAnotherThread() { |
| 65 | 1 |
Thread th = new Thread(new Runnable() { |
| 66 | 1 |
public void run() { |
| 67 | 1 |
try {
|
| 68 | 1 |
assertTrue("This fails from another thread", false); |
| 69 |
} catch (Throwable throwable) {
|
|
| 70 | 1 |
setError(throwable); |
| 71 |
} |
|
| 72 | 1 |
m_done = true;
|
| 73 |
} |
|
| 74 |
}, "Assert from this thread.");
|
|
| 75 | 1 |
th.start(); |
| 76 | 1 |
while (!m_done) {
|
| 77 | 1 |
sleep(25); |
| 78 |
} |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/**
|
|
| 82 |
* Force a failure.
|
|
| 83 |
* @throws Throwable throws the failure.
|
|
| 84 |
*/
|
|
| 85 | 1 |
public void testFail() throws Throwable { |
| 86 | 1 |
fail("Forced failure");
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/**
|
|
| 90 |
* Main method for running this test case.
|
|
| 91 |
* @param args No arguments are required.
|
|
| 92 |
*/
|
|
| 93 | 0 |
public static void main(final String[] args) { |
| 94 | 0 |
junit.textui.TestRunner.run(FromAnotherThread.class);
|
| 95 |
} |
|
| 96 |
} |
|
| 97 |
|
|
||||||||||