Question: JUnit tests - How would I write a JUnit test on this code to simulate drawing all of the cards in the deck. Code from
JUnit tests - How would I write a JUnit test on this code to simulate drawing all of the cards in the deck. Code from a game of RISK in development for a project. **CODE SNIPPET **
public String drawCard() { if(TERRITORY_CARDS.isEmpty()){ return "No more cards"; } else { // Chooses a random number between 0 and the REMAINING_COUNTRIES Random rand = new Random(); int cardNum = rand.nextInt(REMAINING_COUNTRIES); // Store the selected country in a temporary string String cardCountry = TERRITORY_CARDS.get(cardNum); String cardType = TERRITORY_TYPE.get(cardNum); this.cardCountry = cardCountry; this.cardType = cardType; TERRITORY_CARDS.remove(cardNum); // Remove the selected country from the deck TERRITORY_TYPE.remove(cardNum); REMAINING_COUNTRIES--; // Update the size of the deck return "[" + getCardCountry() + " -> " + getCardType() + "]"; } } **JUNIT TEST** import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class GamePlayTest { @Test void throwDice() { } @Test void playDiceRoll() { } @Test void drawCard() { } @Test void getCardType() { } @Test void getCardCountry() { } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
