package rocks.zipcode; import org.junit.Assert; import org.junit.Test; public class BlackJackRuleTest { @Test public void testIsBusted_whenPlayerHas21(){ // Given - set up data Player player = new Player(); player.addCard(new Cards(Cards.Rank.ACE, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); BlackJackRule rule = new BlackJackRule(); // When - invoke method boolean actual = rule.isBusted(player); // Then - verify result Assert.assertFalse(actual); } @Test public void testIsBusted_whenScoreIsOver21(){ // Given - set up data Player player = new Player(); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.CLUBS)); BlackJackRule rule = new BlackJackRule(); // When - invoke method boolean actual = rule.isBusted(player); // Then - verify result Assert.assertTrue(actual); } @Test public void testGetWinner_whenPlayerIsBustedAndDealerIsNot(){ //Given - setup data Player player = new Player("Player 1"); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.CLUBS)); Player dealer = new Player("Dealer"); dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.DIAMONDS)); BlackJackRule rule = new BlackJackRule(); //When - invoke method Player winner = rule.getWinner(dealer, player); //Then - verify result Assert.assertEquals(dealer, winner); } @Test public void testGetWinner_whenPlayerAndDealerAreBusted(){ //Given - setup data Player player = new Player("Player 1"); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.CLUBS)); Player dealer = new Player("Dealer"); dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.DIAMONDS)); BlackJackRule rule = new BlackJackRule(); //When - invoke method Player winner = rule.getWinner(dealer, player); //Then - verify result Assert.assertNull(winner); } @Test public void testGetWinner_whenPlayerHandIsHigherThanDealer(){ //Given - setup data Player player = new Player("Player 1"); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); Player dealer = new Player("Dealer"); dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.NINE, Cards.Suit.DIAMONDS)); BlackJackRule rule = new BlackJackRule(); //When - invoke method Player winner = rule.getWinner(dealer, player); //Then - verify result Assert.assertEquals(player, winner); } @Test public void testGetWinner_whenDealerHandIsHigherThanPlayer(){ //Given - setup data Player player = new Player("Player 1"); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); Player dealer = new Player("Dealer"); dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.ACE, Cards.Suit.DIAMONDS)); BlackJackRule rule = new BlackJackRule(); //When - invoke method Player winner = rule.getWinner(dealer, player); //Then - verify result Assert.assertEquals(dealer, winner); } @Test public void testGetWinner_whenDealerIsTheSameAsPlayer(){ //Given - setup data Player player = new Player("Player 1"); player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS)); player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS)); Player dealer = new Player("Dealer"); dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS)); dealer.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.DIAMONDS)); BlackJackRule rule = new BlackJackRule(); //When - invoke method Player winner = rule.getWinner(dealer, player); //Then - verify result Assert.assertNull(winner); } }