Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when calling an overridden contract method - most likely missing the target reference #25

Closed
BenRomberg opened this issue Jun 2, 2012 · 0 comments
Assignees
Milestone

Comments

@BenRomberg
Copy link
Member

Example - assert getX() should really be assert target.getX():

public class A {

    private int x;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

}

import static de.andrena.c4j.Condition.postCondition;
import static de.andrena.c4j.Condition.preCondition;
import de.andrena.c4j.Target;

public class AContract extends A {

    @Override
    public void setX(int x) {
        if (preCondition()) {
            assert x > 0 : "x > 0";
        }
        if (postCondition()) {
            assert getX() == x : "x set";
        }
    }

}

import org.junit.Test;

public class ATest {

    @Test
    public void test() {
        A a = new A();
        a.setX(5);
    }

}
@ghost ghost assigned BenRomberg Jun 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant