I am new to programming and have a noob question. I am trying to run a test like so...
@Test
public void rememberTest()
throws DuplicateException{
try{
personA.remember(sighting4);
}
catch (Exception e) {
fail("Failed" + e.getMessage());
}
try{
assertEquals(personA.remember(sighting3), "The list already contains this sighting");
}
catch (Exception e) {
fail("Failed" + e.getMessage());
}
}
the first try/catch compiles but the second one does not. It tells me "'void' type not allowed here. " Why can't I use a void? If I can't use a void type, then how would I build my test so that the exception is thrown?
some background info: rememberTest is a test of the remember method that adds an item to an ArrayList.
the remember method, in Class Person, is as follows:
public void remember(final Sighting s)
throws DuplicateException
{
if(lifeList.contains(s)) {
throw new DuplicateException("The list already contains this sighting");
}
lifeList.remember(s);
}
If you need more info please request and I will post it as required.
since you method has already ensured that no duplicate value will be added then I suggest to remove the
assertEquals
from your code,to demonstrate edit your code to this: