SWE 619 In Class Exercise Number 11


This is a JUnit theory exercise.

  1. Get some JUnit theory working in your favorite Java environment. Here's some possible code.
    See Chapter 3 for the example explained in class.
  2. Write a JUnit theory that captures the symmetry property of the equals() method.
  3. Create @DataPoints from an example that breaks symmetry: Point2.java
    So that we're all on the same page, create 1 null reference, 1 Point1 object and 2 Point2 objects. Your example should demonstrate the symmetry failure.
  4. Given this set of data points:
    • How many combinations are considered by the theory?
    • How many combinations make it past the preconditions of the theory?
    • How many combinations make it to the postcondition of the theory?
  5. What happens to this theory and the accompanying data points when favoring composition over inheritance?
  6. Write a JUnit theory for the transitive property for equals().
  7. Recall the equals() and hashCode() discussion in Bloch. Write a JUnit theory that encodes the consistency property between equals() and hashCode().
  8. Build a toy example that violates the theory. Fix the toy example so that the theory is no longer violated.
  9. Consider the Comparable interface: what properties should be checked with theories?