tests the state checking and uses SplitTime
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
64fa7bc607
commit
8b361b4134
|
@ -24,7 +24,7 @@ import junit.textui.TestRunner;
|
||||||
* TestCase for StopWatch.
|
* TestCase for StopWatch.
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @version $Id: StopWatchTest.java,v 1.7 2004/02/18 23:03:03 ggregory Exp $
|
* @version $Id: StopWatchTest.java,v 1.8 2004/09/05 19:55:29 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class StopWatchTest extends TestCase {
|
public class StopWatchTest extends TestCase {
|
||||||
|
|
||||||
|
@ -73,14 +73,13 @@ public class StopWatchTest extends TestCase {
|
||||||
watch.start();
|
watch.start();
|
||||||
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
||||||
watch.split();
|
watch.split();
|
||||||
long splitTime = watch.getTime();
|
long splitTime = watch.getSplitTime();
|
||||||
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
||||||
watch.unsplit();
|
watch.unsplit();
|
||||||
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
try {Thread.sleep(550);} catch (InterruptedException ex) {}
|
||||||
watch.stop();
|
watch.stop();
|
||||||
long totalTime = watch.getTime();
|
long totalTime = watch.getTime();
|
||||||
|
|
||||||
// System.err.println(splitTime +" "+totalTime);
|
|
||||||
assertTrue(splitTime >= 500);
|
assertTrue(splitTime >= 500);
|
||||||
assertTrue(splitTime < 700);
|
assertTrue(splitTime < 700);
|
||||||
assertTrue(totalTime >= 1500);
|
assertTrue(totalTime >= 1500);
|
||||||
|
@ -99,11 +98,80 @@ public class StopWatchTest extends TestCase {
|
||||||
watch.stop();
|
watch.stop();
|
||||||
long totalTime = watch.getTime();
|
long totalTime = watch.getTime();
|
||||||
|
|
||||||
// System.err.println(suspendTime +" "+totalTime);
|
|
||||||
assertTrue(suspendTime >= 500);
|
assertTrue(suspendTime >= 500);
|
||||||
assertTrue(suspendTime < 700);
|
assertTrue(suspendTime < 700);
|
||||||
assertTrue(totalTime >= 1000);
|
assertTrue(totalTime >= 1000);
|
||||||
assertTrue(totalTime < 1300);
|
assertTrue(totalTime < 1300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test bad states
|
||||||
|
public void testBadStates() {
|
||||||
|
StopWatch watch = new StopWatch();
|
||||||
|
try {
|
||||||
|
watch.stop();
|
||||||
|
fail("Calling stop on an unstarted StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.stop();
|
||||||
|
fail("Calling stop on an unstarted StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.suspend();
|
||||||
|
fail("Calling suspend on an unstarted StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.unsplit();
|
||||||
|
fail("Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.resume();
|
||||||
|
fail("Calling resume on an unsuspended StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
watch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.start();
|
||||||
|
fail("Calling start on an started StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.unsplit();
|
||||||
|
fail("Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.getSplitTime();
|
||||||
|
fail("Calling getSplitTime on an unsplit StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
watch.resume();
|
||||||
|
fail("Calling resume on an unsuspended StopWatch should throw an exception. ");
|
||||||
|
} catch(IllegalStateException ise) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue