assertTrue("Completed timer has no totalTime", timer.getTime() >= 0);
}
public void testRestart() throws Exception {
Long skipAhead = 60L * 60L * 1000000000L;
Timer timer = new Timer("foo");
//this test is a little funky to avoid the need for Thread.sleep()
//a second timer is used as somewhat of a control.
timer.start();
assertEquals("Running timer has a totalTime", -1, timer.getTime());
//since totalTime is initially negative even if no time has passed
//it will change to '0' and this test will pass
timer.stop();
assertTrue("Completed timer has no totalTime", timer.getTime() >= 0);
Field totalTime = Timer.class.getDeclaredField("totalTime");
totalTime.setAccessible(true);
totalTime.setLong(timer, skipAhead); //assure value > 0 + likely thread down time
Timer innerTimer = new Timer("bar");
timer.start();
innerTimer.start();
innerTimer.stop(); //probably '0' totalTime but it could be a whole lot more
timer.stop();
//if reset is broken in the future this test becomes flappable with false passes
//that would be the case if the innerTimer above waited for 1h less that the timer under test.
//this is extremely unlikely.
assertTrue("Timer restart did not accumulate time", timer.getTime() >= ((skipAhead / 1000000L) + innerTimer.getTime()));
}