Question: JAVA JUNIT TEST HELP - Looking to write some JUNIT tests on this piece of code that is a small part of a Game of

JAVA JUNIT TEST HELP - Looking to write some JUNIT tests on this piece of code that is a small part of a Game of RISK project. I am terrible at writing JUnit tests so any input would be amazing ** CODE SNIPPET **

import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; public class GamePlay { private String cardType; private String cardCountry; private final List TERRITORY_CARDS = new ArrayList<>(Arrays.asList(GameData.COUNTRY_NAMES)); private final List TERRITORY_TYPE = new ArrayList<>(Arrays.asList(CARD_TYPE)); private int REMAINING_COUNTRIES = GameData.COUNTRY_NAMES.length; private static final String[] CARD_TYPE = { "Cavalry","Artillery","Artillery","Infantry","Cavalry","Artillery","Infantry","Cavalry","Infantry", "Cavalry","Infantry","Cavalry","Artillery","Cavalry","Infantry","Artillery", "Infantry","Infantry","Artillery","Infantry","Cavalry","Cavalry","Cavalry","Artillery","Infantry","Artillery","Artillery","Cavalry", "Infantry","Cavalry","Artillery","Cavalry", "Artillery","Cavalry","Artillery","Infantry", "Cavalry","Infantry","Artillery","Infantry","Artillery","Infantry"}; // for reference public static final String[] ABBREV_COUNTRY_NAMES = { "On","Qu","NWT","Alb","Gr","EUS","WUSt","CAm","Al", "GB","WEu","SEu","Ukr","NEu","Ice","Sca", "Afg","In","ME","Ja","Ur","Ya","Ka","Si","Irk","Sib","Mon","Ch", "EAu","NGu","WAu","Ind", "Ve","Pe","Bra","Arg", "Co","NAf","SAf","Eg","EAf","Mad"}; public static int throwDice() { // Generates a random number between 1 - 6 Random rand = new Random(); return rand.nextInt(6)+1; } public static void playDiceRoll() { try { Clip dice = AudioSystem.getClip(); AudioInputStream input = AudioSystem.getAudioInputStream(GamePlay.class.getResourceAsStream("diceRoll.wav")); dice.open(input); dice.start(); } catch (Exception e) { e.printStackTrace(); } } 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 "[" + cardCountry + " -> " + cardType + "]"; } } public String getCardType(){ return cardType; } public String getCardCountry(){ return cardCountry; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!