1 package org.columba.core.util; 17 18 import junit.framework.TestCase; 19 20 import org.columba.core.base.StopWatch; 21 22 23 30 public class StopWatchTest extends TestCase { 31 35 public void testStop() throws InterruptedException { 36 StopWatch watch = new StopWatch(); 37 StopWatch watch2 = new StopWatch(); 38 watch2.stop(); 39 40 Thread.sleep(50); 41 42 long difference = watch.getTiming() - watch2.getTiming(); 43 44 if (Math.abs(difference) < 40) { 45 fail("Stopwatch wasnt stopped."); 46 } 47 } 48 49 53 public void testStart() throws InterruptedException { 54 StopWatch watch = new StopWatch(); 55 StopWatch watch2 = new StopWatch(); 56 watch.stop(); 57 watch2.stop(); 58 watch2.start(); 59 60 Thread.sleep(50); 61 62 long difference = watch.getTiming() - watch2.getTiming(); 63 64 if (Math.abs(difference) < 40) { 65 fail("Stopwatch wasnt restarted correctly."); 66 } 67 } 68 69 73 public void testTiming() throws InterruptedException { 74 StopWatch watch = new StopWatch(); 75 76 Thread.sleep(50); 77 watch.stop(); 78 79 if (watch.getTiming() < 50) { 80 fail("Stopwatch returned too small value. expected < 50 but was <" + 81 watch.getTiming() + ">"); 82 } 83 } 84 } 85 | Popular Tags |