bayard      2004/09/05 12:55:29

  Modified:    lang/src/test/org/apache/commons/lang/time
                        StopWatchTest.java
  Log:
  tests the state checking and uses SplitTime
  
  Revision  Changes    Path
  1.8       +72 -4     
jakarta-commons/lang/src/test/org/apache/commons/lang/time/StopWatchTest.java
  
  Index: StopWatchTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/StopWatchTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StopWatchTest.java        18 Feb 2004 23:03:03 -0000      1.7
  +++ StopWatchTest.java        5 Sep 2004 19:55:29 -0000       1.8
  @@ -73,14 +73,13 @@
           watch.start();
               try {Thread.sleep(550);} catch (InterruptedException ex) {}
           watch.split();
  -        long splitTime = watch.getTime();
  +        long splitTime = watch.getSplitTime();
               try {Thread.sleep(550);} catch (InterruptedException ex) {}
           watch.unsplit();
               try {Thread.sleep(550);} catch (InterruptedException ex) {}
           watch.stop();
           long totalTime = watch.getTime();
           
  -//        System.err.println(splitTime +"  "+totalTime);
           assertTrue(splitTime >= 500);
           assertTrue(splitTime < 700);
           assertTrue(totalTime >= 1500);
  @@ -99,11 +98,80 @@
           watch.stop();
           long totalTime = watch.getTime();
           
  -//        System.err.println(suspendTime +"  "+totalTime);
           assertTrue(suspendTime >= 500);
           assertTrue(suspendTime < 700);
           assertTrue(totalTime >= 1000);
           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
  +        }
  +
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to