package com.sparcs.casino.roulette;

import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

import java.util.List;
import java.util.Optional;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.sparcs.casino.BaseTest;
import com.sparcs.casino.Customer;
import com.sparcs.casino.game.GameType;
import com.sparcs.casino.game.Player;
import com.sparcs.casino.game.Room;
import com.sparcs.casino.game.Spectator;

/**
 * A vehicle for prototyping the Roulette API!
 *   
 * @author Lee Newfeld
 */
public class VisitToTheCasinoTest extends BaseTest {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(VisitToTheCasinoTest.class);

    @Autowired
    protected RouletteHall hall;

	@Before
    public void beforeTest() {

		super.beforeTest();
		
        // Add mock functionality
        when(casino.findRooms(any(Customer.class), eq(GameType.ROULETTE))).thenReturn(hall.getRooms());
    }

	@Test
	public void shouldHaveAnEnjoyableTime() {

        // Lee enters the Casino
        Customer customer = casino.signIn("Lee", "abc");
        
        // He wants to play Roulette, where's the action?
        List<Room> rooms = casino.findRooms(customer, GameType.ROULETTE);
        
        // Find an empty room...
        Optional<Room> firstEmptyRoom =
        		rooms.stream()
        			 .filter(r -> r.isEmpty())
        			 .findFirst();
        
        RouletteRoom room = (RouletteRoom)firstEmptyRoom.get();

        // Go inside...
        Spectator spectator = room.enter(lee);
        
        // Meet the Croupier...
        @SuppressWarnings("unused")
		RouletteCroupier croupier = (RouletteCroupier)room.getGameManager();

        // Take a chair
        Player player = room.joinGame(spectator);
        
        // Run a cycle of all game loops
        while( hall.executeGameLoops() ) {
        	
        }

        // Stand up
        spectator = room.leaveGame(player);

        // Leave the room
        room.exit(spectator);

        // Go home
        casino.signOut(customer);
	}
}

@@ -30,16 +30,50 @@
 lette;%0A%0A
+import static org.junit.Assert.*;%0A
 import s
@@ -1985,15 +1985,66 @@
     
-whil
+for( int i=0; i%3C50; i++ ) %7B%0A        %09%0A        %09assertTru
 e(
- 
 hall
@@ -2062,30 +2062,18 @@
 eLoops()
- ) %7B%0A        %09
+);
 %0A       

Fix infinite loop in VisitCasino 'test' (*blush*)