Commit 67367c30 by Graham Lee

Make errors more specific

parent f20967cd
......@@ -89,7 +89,7 @@ public class ContractEnforcer implements InvocationHandler {
boolean expectedValue = precondition.value();
Boolean actualValue = findAndInvokeMethod(methodName, targetClass, target, arguments);
if (actualValue != expectedValue) {
throw new ContractViolationException(target, methodName, actualValue);
throw new ContractViolationException(target, Precondition.class.getName(), methodName, actualValue);
}
}
// run the method
......@@ -105,7 +105,7 @@ public class ContractEnforcer implements InvocationHandler {
argsWithReturnValue[arguments.length] = result;
Boolean actualValue = findAndInvokeMethod(methodName, targetClass, target, argsWithReturnValue);
if (actualValue != expectedValue) {
throw new ContractViolationException(target, methodName, actualValue);
throw new ContractViolationException(target, Postcondition.class.getName(), methodName, actualValue);
}
}
// check the invariants
......@@ -114,7 +114,7 @@ public class ContractEnforcer implements InvocationHandler {
boolean expectedValue = invariant.value();
Boolean actualValue = findAndInvokeMethod(methodName, targetClass, target, null);
if (actualValue != expectedValue) {
throw new ContractViolationException(target, methodName, actualValue);
throw new ContractViolationException(target, Invariant.class.getName(), methodName, actualValue);
}
}
return result;
......
......@@ -6,8 +6,8 @@ package online.labrary.javaByContract;
public class ContractViolationException extends Error {
public ContractViolationException(Object target, String methodName, Boolean actualValue) {
super(String.format("Invariant %s had unexpected value %b on object %s", methodName, actualValue, target));
public ContractViolationException(Object target, String contractComponent, String methodName, Boolean actualValue) {
super(String.format("%s %s had unexpected value %b on object %s", contractComponent, methodName, actualValue, target));
}
private static final long serialVersionUID = 1L;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment