I have a method that expects some invariants to be preserved during a certain processing point.
To keep this trivial, let's say that at point X, during the processing of the code, the variable highand the variable lowMUST be divisible.
So in the code I do:
if(high % low != 0){
throw new AssertionError("Invalid state of low and high [low = "+ low+ ", high=" + high+"]");
}
During unit testing with help JUnits, I had a test case to test this.
So I did:
try {
process();
fail();
}
catch(AssertionError e){
}
!
, junit assert - fail, , - .
, AssertionError, - , . IllegalArgumentsException
, , , AssertionError ? , ?