/*
 * Copyright © 2012 Sebastian Hoß <mail@shoss.de>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.github.sebhoss.contract.example;

import com.github.sebhoss.contract.annotation.Clause;
import com.github.sebhoss.contract.annotation.Contract;
import com.github.sebhoss.contract.annotation.OGNL;
import com.github.sebhoss.contract.annotation.SpEL;

@OGNL
@SpEL
class OgnlSpELBasedInsuranceCompany extends AbstractInsuranceCompany {

    @Contract(preconditions = {
            @Clause(value = "#damage > 0", message = "Reported damage must be positive!", exception = IllegalStateException.class),
            @Clause(value = "#damage <= 5000", message = "We won't pay that!") }, postconditions = {
            @Clause(value = "#return >= 0", message = "We won't take any more!"),
            @Clause(value = "#return <= 2000", message = "We can't pay that much!") })
    @Override
    public double calculateCover(final double damage) {
        return damage * 0.5;
    }

}

/*
 * Copyright © 2012 Sebastian Hoß <mail@shoss.de>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.github.sebhoss.contract.example;

import com.github.sebhoss.contract.annotation.Clause;
import com.github.sebhoss.contract.annotation.Contract;
import com.github.sebhoss.contract.annotation.OGNL;
import com.github.sebhoss.contract.annotation.SpEL;

@OGNL
@SpEL
class OgnlSpELBasedInsuranceCompany extends AbstractInsuranceCompany {

    @Contract(preconditions = {
            @Clause(value = "#damage > 0", message = "Reported damage must be positive!", exception = IllegalStateException.class),
            @Clause(value = "#damage <= maximumReportableDamage", message = "We won't pay that!") }, postconditions = {
            @Clause(value = "#return >= 0", message = "We won't take any more!"),
            @Clause(value = "#return <= remainingMoney", message = "We can't pay that much!") })
    @Override
    public double calculateCover(final double damage) {
        return damage * 0.5;
    }

}

Use instance methods in contract
Use instance methods in contract

Signed-off-by: Sebastian Hoß <1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e@shoss.de>