@Test
 public void players_can_place_bets_when_the_ball_starts_rolling_up_to_10_seconds()
     throws Exception {
   rt.roll();
   timer.moveTime(5000);
   rt.placeBet(p, Field.forNumber(1), 1);
 }
  @Test
  public void winning_bets_contain_all_bets_with_field_winning_strategy_covering_ball_position()
      throws Exception {
    // arrange
    Player p2 = new Player();
    Player p3 = new Player();

    WinningStrategy loses = mock(WinningStrategy.class);
    when(loses.winsOn(anyInt())).thenReturn(false);

    WinningStrategy wins = mock(WinningStrategy.class);
    when(wins.winsOn(anyInt())).thenReturn(true);

    rt.placeBet(p, new Field("A", loses, 36), 1);
    rt.placeBet(p2, new Field("B", wins, 36), 2);
    rt.placeBet(p3, new Field("C", loses, 36), 3);
    // act
    when(rng.generate(30, 40)).thenReturn(33);
    rt.roll();
    timer.moveTime(34000);
    // assert
    Set<Bet> winningBets = new HashSet<Bet>();
    winningBets.add(new Bet(p2, 2));
    assertEquals(winningBets, rt.getWinningBets());
  }
 @Test
 public void ball_rolls_for_a_random_time_between_30_and_40_seconds() throws Exception {
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(33001);
   assertFalse(rt.isBallRolling());
 }
 @Test(expected = NoMoreBetsException.class)
 public void players_cannot_place_bets_when_the_ball_starts_rolling_after_10_seconds()
     throws Exception {
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(10001);
   rt.placeBet(p, Field.forNumber(1), 1);
 }
 @Test
 public void system_will_not_pay_out_anything_for_losing_bets() throws Exception {
   WinningStrategy loses = mock(WinningStrategy.class);
   when(loses.winsOn(anyInt())).thenReturn(false);
   rt.placeBet(p, new Field("B", loses, 3), 2);
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(34000);
   verify(walletService, times(1)).adjustBalance(eq(p), anyInt());
 }
 @Test
 public void game_gets_a_random_outcome_when_the_ball_stops_rolling() {
   // act
   when(rng.generate(0, 36)).thenReturn(13);
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(34000);
   // assert
   assertEquals(13, rt.getBallPosition());
 }
 @Test
 public void system_will_automatically_pay_out_winning_bets_with_multiplier_on_field()
     throws Exception {
   WinningStrategy wins = mock(WinningStrategy.class);
   when(wins.winsOn(anyInt())).thenReturn(true);
   rt.placeBet(p, new Field("B", wins, 3), 2);
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(34000);
   verify(walletService).adjustBalance(p, -2);
   verify(walletService).adjustBalance(p, 6);
 }
 @Test
 public void multibets_paid_out_divided_by_number_of_fields() throws Exception {
   WinningStrategy loses = mock(WinningStrategy.class);
   when(loses.winsOn(anyInt())).thenReturn(false);
   WinningStrategy wins = mock(WinningStrategy.class);
   when(wins.winsOn(anyInt())).thenReturn(true);
   rt.placeBet(p, new Field[] {new Field("1", wins, 36), new Field("2", loses, 36)}, 1);
   when(rng.generate(30, 40)).thenReturn(33);
   rt.roll();
   timer.moveTime(34000);
   verify(walletService).adjustBalance(p, -1);
   verify(walletService).adjustBalance(p, 18);
 }