Currently I am working on a JUnitTest class for one of my projects and need to test every throw and true or false and so on. I have a load and save method that works correctly but I need to get the method to not work and show that in a test method.
Here's my load and save methods,
My test case is this
But like I said I am trying to get 100 percent coverage in my code and need to get the save and load methods to run this line to prove that if it is actually wrong it will say something is wrong.
I have tried this but It does not work so what am I doing wrong?
The only way I can see to get that method to fail is to have the test attempt to write to a file it is not allowed to write to.
That might be a slightly fragile test (it's reliant on a specific set up of file and user), but it's the only way that comes to mind at the moment.
Edit: That's for the save method.
For the load method it should throw a FileNotFoundException if the file does not exist, which I would expect to be the case here?