Skip to content

Instantly share code, notes, and snippets.

@daveneedstoknow
Created April 19, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveneedstoknow/7588d8c6f3ae1faea4faf26c692082a8 to your computer and use it in GitHub Desktop.
Save daveneedstoknow/7588d8c6f3ae1faea4faf26c692082a8 to your computer and use it in GitHub Desktop.
import org.junit.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.AdditionalMatchers.*;
import org.mockito.InOrder;
public class TickProviderTest {
@Test
public void shouldNotifyTickWhenStarted() {
RouletteWheel rouletteWheel = mock(RouletteWheel.class);
TickProvider tickProvider = new TickProvider(rouletteWheel);
tickProvider.start();
verify(rouletteWheel, timeout(150).atLeastOnce()).tick(anyInt());
}
@Test
public void shouldNotifyTickEvery100ms() throws Exception {
RouletteWheel rouletteWheel = mock(RouletteWheel.class);
TickProvider tickProvider = new TickProvider(rouletteWheel);
tickProvider.start();
verify(rouletteWheel, timeout(500).atLeast(5)).tick(anyInt());
}
@Test
public void shouldIncrementEachTickByApprox100() throws Exception {
RouletteWheel rouletteWheel = mock(RouletteWheel.class);
TickProvider tickProvider = new TickProvider(rouletteWheel);
InOrder inOrder = inOrder(rouletteWheel,
rouletteWheel,
rouletteWheel);
tickProvider.start();
Thread.sleep(200);
inOrder.verify(rouletteWheel)
.tick(and(gt((long)0), lt((long)20)));
inOrder.verify(rouletteWheel)
.tick(and(gt((long)90), lt((long)120)));
inOrder.verify(rouletteWheel)
.tick(and(gt((long)190), lt((long)220)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment