[[invariant:intro|Intro]]
[[invariant:ex1|Ex1]]
[[invariant:ex2|Ex2]]
[[invariant:ex3|Ex3]]
[[invariant:ex4|Ex4]]
[[invariant:ex5|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 [[invariant:ex4|Exercise 4]].