This is my test so far:
@Test(expected = FileNotFoundException.class)
public void testExpectedException() {
UserDataObject u = new UserDataObject(\"rob123\",
Your test is failing because you are expecting the FileNotFoundException, but it not actualy thrown from a method. Why? Because of try/catch wrapper, that swallows the exception, only printing the stack trace to the output.
Change the catch block to
catch (FileNotFoundException e) {
System.out.println("Error: Could not find database/storage.");
System.out.println(e.getMessage());
throw e;
}
and test will pass
The issue is that your verifyUser(UserDataObject u, String filename)
method catches both exceptions FileNotFoundException
and IOException
and hence it is not propagated to your test method.