I have the following test –
public void testStore() throws ItemNotStoredException {
Boolean result = itemSrvc.storeItem(items);
Assert.assertFalse(result);
}
but I get the error Type mismatch: cannot convert from void to Boolean.
What it is testing…
public void storeItem(Items items) throws ItemNotStoredException {
try {
ObjectOutputStream output = new
ObjectOutputStream (new FileOutputStream ("itemdatabase"));
output.writeObject(items);
output.flush();
output.close();
} catch (IOException e) {
throw new ItemNotStoredException ("Unable to store file", e);
}
}
To clarify – I dont want storeItem to return anything, I am just trying to test it, so perhaps my test itself is just wrong. If that is the case, any advise on how to fix the test would be greatly appreciated.
If you want to test the case when the save fails, and assuming that an exception should get thrown if the save fails, then you could change the test to look like this:
or if you’re using an ancient version of JUnit: