Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package com.techelevator; import static org.junit.Assert. * ; import org.junit.Before; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import java.lang.reflect. * ; @FixMethodOrder ( MethodSorters . NAME _
package com.techelevator;
import static org.junit.Assert.;
import org.junit.Before;
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import java.lang.reflect.;
@FixMethodOrderMethodSortersNAMEASCENDING
public class CheckingAccountTest
private final String PACKAGENAME "com.techelevator";
private final String BANKACCOUNTCLASSNAME "BankAccount";
private final String CHECKINGACCOUNTCLASSNAME "CheckingAccount";
private static Class checkingAccountClass;
@Before
public void Initialize
try
checkingAccountClass Class.forNamePACKAGENAME CHECKINGACCOUNTCLASSNAME;
catch ClassNotFoundException e
failegetMessage class could not be found. Have you declared it yet? Make sure the class name is CHECKINGACCOUNTCLASSNAME and the package name is PACKAGENAME ;
@Test
public void testClassWellFormed
String wellFormedCheck classWellFormedCheck;
if wellFormedCheck.isEmpty
failwellFormedCheck;
@Test
public void testHappyPathTests throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException
String wellFormedCheck classWellFormedCheck;
if wellFormedCheck.isEmpty
failCHECKINGACCOUNTCLASSNAME is not well formed. The testClassWellFormed tests must pass first.r
t wellFormedCheck;
Assert constructors set fields
String testAccountHolderName "Tester Testerson";
String testAccountNumber CHK:;
int testBalance ;
Two arg constructor
Constructor twoArgConstructor SafeReflection.getConstructorcheckingAccountClass String.class, String.class;
Object twoArgInstance twoArgConstructor.newInstancetestAccountHolderName testAccountNumber;
Method twoArgGetAccountHolderName twoArgInstance.getClassgetMethodgetAccountHolderName;
assertEqualsCHECKINGACCOUNTCLASSNAME constructor CHECKINGACCOUNTCLASSNAME String String does not correctly set the field accountHolderName.",
testAccountHolderName, twoArgGetAccountHolderName.invoketwoArgInstance;
Method twoArgGetAccountNumber twoArgInstance.getClassgetMethodgetAccountNumber;
assertEqualsCHECKINGACCOUNTCLASSNAME constructor CHECKINGACCOUNTCLASSNAME String String does not correctly set the field accountNumber.",
testAccountNumber, twoArgGetAccountNumber.invoketwoArgInstance;
Three arg constructor
Constructor threeArgConstructor SafeReflection.getConstructorcheckingAccountClass String.class, String.class, int.class;
Object threeArgInstance threeArgConstructor.newInstancetestAccountHolderName testAccountNumber, testBalance;
Method threeArgGetAccountHolderName threeArgInstance.getClassgetMethodgetAccountHolderName;
assertEqualsCHECKINGACCOUNTCLASSNAME constructor CHECKINGACCOUNTCLASSNAME String String, int does not correctly set the field accountHolderName.",
testAccountHolderName, threeArgGetAccountHolderName.invokethreeArgInstance;
Method threeArgGetAccountNumber threeArgInstance.getClassgetMethodgetAccountNumber;
assertEqualsCHECKINGACCOUNTCLASSNAME constructor CHECKINGACCOUNTCLASSNAME String String, int does not correctly set the field accountNumber.",
testAccountNumber, threeArgGetAccountNumber.invokethreeArgInstance;
Method threeArgGetBalance threeArgInstance.getClassgetMethodgetBalance;
assertEqualsCHECKINGACCOUNTCLASSNAME constructor CHECKINGACCOUNTCLASSNAME String String, int does not correctly set the field balance.",
testBalance, threeArgGetBalance.invokethreeArgInstance;
Assert withdraw decreases balance
Method withdraw threeArgInstance.getClassgetMethodwithdraw int.class;
int withdrawParamValue ;
int withdrawExpectedReturnValue testBalance withdrawParamValue;
Object withdrawActualReturnValue withdraw.invokethreeArgInstance withdrawParamValue;
assertEqualsCHECKINGACCOUNTCLASSNAME withdraw method fails to decrease balance by correct amount. Starting balance: testBalance withdraw: withdrawParamValue new balance should be withdrawExpectedReturnValue
withdrawExpectedReturnValue, withdrawActualReturnValue;
@Test
public void testEdgeCaseTests throws IllegalAccessException, InvocationTargetException, InstantiationException
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started