My TEST creates an instance of SimpleTimer with 1000 as a milliseconds measure to delay the thread by 1 second.
@Test
public void testSimpleTimerAsThread() throws InterruptedException
{
SimpleTimer st = new SimpleTimer(1000);
st.start();
Thread.sleep(250);
for(int x = 0; x<5; x++)
{
assertEquals(x, st.getRound());
Thread.sleep(1000);
}
}
My METHOD
timeChanged() just updates the round number and calls for all observers to update their time.
public void start()
{
for(int r = 0; r<5; r++)
{
try
{
timeChanged();
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
}
SimpleTimer extends Thread and implements an interface that doesn't really mess with this code.
When I run this i get the java assertion error saying it expected 0 but was 5 so x never incremented and the round increased by 5.