Question: How to perform Junit test of this code? kindly solve this. package com.company ; import java.util.ArrayList ; public class Jail extends Square { private ArrayList
How to perform Junit test of this code? kindly solve this.
| package com.company; | |
| import java.util.ArrayList; | |
| public class Jail extends Square { | |
| private ArrayList<Player> playersInJail; | |
| public Jail() { | |
| super(); | |
| playersInJail = new ArrayList<>(); | |
| } | |
| public String getSquareDetails() { | |
| return "This is a jail!"; | |
| } | |
| //getters and setters | |
| public ArrayList<Player> getPlayersInJail() | |
| { | |
| return this.playersInJail; | |
| } | |
| public boolean isPlayerInJail(Player player) { | |
| for (Player playerInJail : playersInJail) { | |
| if (playerInJail == player) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| //additional methods | |
| public void putPlayerInJail(Player p) | |
| { | |
| this.playersInJail.add(p); | |
| } | |
| public boolean postBail(Player p) | |
| { | |
| if(p.getMoney()>500) | |
| { | |
| p.addMoney(-200); | |
| this.playersInJail.remove(p); | |
| return true; | |
| } | |
| //else | |
| return false; | |
| } | |
| } |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
