exception with an appropriate message when it is passed a File object that does

Exception with an appropriate message when it is

This preview shows page 4 - 5 out of 5 pages.

* exception with an appropriate message, when it is passed a File object thatdoes not correspond* to an actual file within the file system.* * @return true when test verifies correct functionality, and false otherwise.*/public static boolean testAccountMissingFile() {File badFile = null;try {Account testAccount = new Account(badFile);} catch (FileNotFoundException e) {if (e.getMessage().equals("file is null")) {
Background image
return true;}} catch (DataFormatException e) {}return false;}/** I made this method and created a file that contained some faulty input data. I wanted to be* sure that the file continues reading after it hits a faulty transaction group. However since* the file is a separate file the method would not correctly run when I upload it to zyBooks so I* commented it all out.* * public static boolean testInvalidFile() throws DataFormatException, FileNotFoundException {* File testFile = new File("accountInput"); * Account testAccount = new Account(testFile); * if (testAccount.getTransactionAmount(0) == 10 && testAccount.getTransactionAmount(3) == -3) {* return true; * } return false; * }*//*** Tests the method that adds transactions by providing data that is unable tobe parsed into an* int.* * @return true when test verifies correct functionality, and false otherwise.*/public static boolean testAccountAddUnparsabletransaction() {Account testAccount = new Account("test");try {testAccount.addTransactionGroup("H E L L O");} catch (DataFormatException e) {if (e.getMessage().equals("addTransactionGroup requires string commands that contain only space"+ " separated integer values")) {return true;}}return false;}}
Background image

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '19
  • Subroutine, partner, Formal verification, formal methods, Account testAccount

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture