-
Notifications
You must be signed in to change notification settings - Fork 1
WritingContractsWithUEL
Sebastian Hoß edited this page Oct 5, 2013
·
3 revisions
The Java unified expressions languages demands, that expressions are started with ${
and closed with }
. See the tutorial on how to access object fields and methods.
To reference the enclosing instance of the annotated business class, use the constant this
. To reference the result of the method invocation use the constant return
. The following class shows an example:
class UELInsuranceCompany {
@Contract( preconditions = { @Clause(value = "${damage > 0}", message = "Reported damage must be positive!", exception = IllegalStateException.class), @Clause(value = "${damage <= this.maximumReportableDamage}", message = "We won't pay that!", exception = IllegalStateException.class) }, postconditions = { @Clause(value = "${return >= 0}", message = "We won't take any more!"), @Clause(value = "${return <= this.remainingMoney}", message = "We can't pay that much!") }) public double calculateCover(final double damage) { // some calculations }
public double getMaximumReportableDamage() { // some value }
public double getRemainingMoney() { // some value }
}