-
-
Save daveneedstoknow/7588d8c6f3ae1faea4faf26c692082a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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