User Tools

Site Tools


invariant:ex3

Intro Ex1 Ex2 Ex3 Ex4 Ex5

Invariants: Preconditions

Point Preconditions

Task: Pass the suite tests.PointPreconditions.

Write an aspect to throw an IllegalArgumentException whenever an attempt is made to set one of the int fields of a Point to a value that is less than zero.

Tools: before advice with set and args primitive pointcuts.

This should make the test cases of tests.PointPreconditions pass, which wouldn't without your aspect.

Group Preconditions

Task: Pass the suite tests.GroupPreconditions.

Group is a FigureElement class that encapsulates groups of other figure elements. As such, only actual figure element objects should be added to Group objects. Also, a group cannot be added to itself. Write an aspect to throw an IllegalArgumentException whenever an attempt is made to call Group.add() with a null value, or with the group itself.

Tools: call and args primitive pointcuts; target primitive pointcut to capture the target of the add() call.

This should make the test cases of tests.GroupPreconditions pass.


After you have completed the exercise, remove your aspect from the build path; then continue with Exercise 4.

invariant/ex3.txt · Last modified: 2021/02/05 13:53 by 127.0.0.1