In java, using assertEquals, create unit test cases for the withdraw method in the class below. Use boundary value analysis to find the values to use for input to your test cases.
package assignment7;
//Use boundary value analysis to create junit tests for the assignment.
public class assignment {
private double balance =0;
public double withdraw(double amtToWithdraw) {
if(amtToWithdraw < 0) return 0.0; //can't withdraw a negative amount
if(amtToWithdraw >100.0) return 0.0; //can't withdraw more that $100.00
if(amtToWithdraw%20.0!=0) return 0.0; //can only withdraw in $20 increments
if(amtToWithdraw > this.balance) return 0.0; //can't withdraw more than the balance
else {
this.balance -= amtToWithdraw;
return amtToWithdraw; //return the amount successfully withdrawn
}
}
public void setBalance(double initialBalance) {//set the initial balance value
this.balance = initialBalance;
}
public double getBalance() { // get the current balance value
return this.balance;
}
}
The Junit test file is written below
package assignment7;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class TestAssignment {
assignment a = new assignment();
/*
* Just above and just below boundary values for input
range are -0.01 and 100.01
*
*/
@Test
void testWithdraw() {
//Returns 0.0 as it is just below
lower boundary value
assertEquals(a.withdraw(-0.01),0.0);
//Returns 0.0 as it is just above
upper boundary value
assertEquals(a.withdraw(100.01),0.0);
//Inserting 100.00 as balance
a.setBalance(100.00);
//Returns 100.00 as the value is
just at the boundary value
assertEquals(a.withdraw(100.00),100.00);
//Inserting 0.00 as balance
a.setBalance(100.00);
//Returns 0.00 as the value is just
at the boundary value
assertEquals(a.withdraw(0.00),0.00);
a.setBalance(20.0);
//Returns 0.0 as it is not
divisible by 20.0
assertEquals(a.withdraw(15.0),0.0);
//Returns 0.0 as the withdrawal is
above the balance amount
assertEquals(a.withdraw(21.0),0.0);
//Returns the amount as the
withdrawal is less than or equal to balance
assertEquals(a.withdraw(20.0),20.0);
}
}
The screenshot of the code is given below :-


The output of the test is given below

In java, using assertEquals, create unit test cases for the withdraw method in the class below....