Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write two Junit tests for one method: Write a Passing & Failing Junit Test for the print() method below. Here is an Example Format of
Write two Junit tests for one method:
Write a Passing & Failing Junit Test for the print() method below.
Here is an Example Format of The Junit Tests
void testIsPrintValidPASS() {
//test code
}
void testIsPrintValidFAIL() {
//test code
}
@Override public void print() { String fileContent = 'check# "+this. number+" "+ date: " +this.date+" "+ "payee: "+this.payee+" "+"$ "+this.amount+" "+ "accountID:"+this accountID+" bankID:"+this.bankID+" " + ------"; FileWriter fileWriter = null; try { fileWriter = new FileWriter("CheckFile. txt"); '} catch (IOException exception) { System.out.println("An error occurred.") exception.printStackTrace(); PrintWriter printwriter = new PrintWriter(fileWriter); printWriter.print(fileContent); printwriter.close(); public boolean isPrintvalid() { boolean retValue = true; if(????) { retValue = false; return retValue; // Validations public boolean isAccountIdValid() { boolean retValue = true; if(accountID == null) { retValue = false; return retValue; @Test void testIsAccountIdValidPASS() { Check check = new Check check.setAccountID("myAccount8") boolean expected Result = true; boolean actualResult = check.isAccountIdValid(); assertEquals(expectedResult, actualResult); @Test void testIsAccountIdValidFAILO { Check check = new Check check.setAccountID(nullo boolean expected Result = false; boolean actualResult = check.isAccountIdValid(); assertEquals(expectedResult, actualResult); @Override public void print() { String fileContent = 'check# "+this. number+" "+ date: " +this.date+" "+ "payee: "+this.payee+" "+"$ "+this.amount+" "+ "accountID:"+this accountID+" bankID:"+this.bankID+" " + ------"; FileWriter fileWriter = null; try { fileWriter = new FileWriter("CheckFile. txt"); '} catch (IOException exception) { System.out.println("An error occurred.") exception.printStackTrace(); PrintWriter printwriter = new PrintWriter(fileWriter); printWriter.print(fileContent); printwriter.close(); public boolean isPrintvalid() { boolean retValue = true; if(????) { retValue = false; return retValue; // Validations public boolean isAccountIdValid() { boolean retValue = true; if(accountID == null) { retValue = false; return retValue; @Test void testIsAccountIdValidPASS() { Check check = new Check check.setAccountID("myAccount8") boolean expected Result = true; boolean actualResult = check.isAccountIdValid(); assertEquals(expectedResult, actualResult); @Test void testIsAccountIdValidFAILO { Check check = new Check check.setAccountID(nullo boolean expected Result = false; boolean actualResult = check.isAccountIdValid(); assertEquals(expectedResult, actualResult)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