01: package com.clarkware.junitperf;
02:
03: import junit.framework.TestCase;
04:
05: public class MockTestWithState extends TestCase {
06:
07: private boolean _flag;
08: private int _data;
09:
10: public MockTestWithState(String name) {
11: super (name);
12: }
13:
14: protected void setUp() {
15: _flag = true;
16: _data = 1;
17: }
18:
19: protected void tearDown() {
20: _flag = false;
21: _data = 0;
22: }
23:
24: public void testInvariant() {
25:
26: assertEquals(true, _flag);
27:
28: taskSwitch();
29:
30: assertEquals(1, _data);
31: }
32:
33: protected void taskSwitch() {
34: try {
35: Thread.yield();
36: Thread.sleep(10);
37: } catch (Exception ignore) {
38: }
39: }
40: }
|