Applying test and fix for LANG-315

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@504351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2007-02-06 22:49:50 +00:00
parent de4952beaf
commit b16235ad10
2 changed files with 15 additions and 1 deletions

View File

@ -115,7 +115,9 @@ public class StopWatch {
if(this.runningState != STATE_RUNNING && this.runningState != STATE_SUSPENDED) {
throw new IllegalStateException("Stopwatch is not running. ");
}
stopTime = System.currentTimeMillis();
if(this.runningState == STATE_RUNNING) {
stopTime = System.currentTimeMillis();
}
this.runningState = STATE_STOPPED;
}

View File

@ -108,6 +108,18 @@ public class StopWatchTest extends TestCase {
assertTrue(totalTime < 1300);
}
public void testLang315() {
StopWatch watch = new StopWatch();
watch.start();
try {Thread.sleep(200);} catch (InterruptedException ex) {}
watch.suspend();
long suspendTime = watch.getTime();
try {Thread.sleep(200);} catch (InterruptedException ex) {}
watch.stop();
long totalTime = watch.getTime();
assertTrue( suspendTime == totalTime );
}
// test bad states
public void testBadStates() {
StopWatch watch = new StopWatch();