This is a JUnit theory exercise.
- Get some JUnit theory working in your favorite Java environment.
Here's some
possible code.
See Chapter 3 for the example explained in class.
-
Write a JUnit theory that captures the symmetry property of the
equals()
method.
-
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.
-
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?
-
What happens to this theory and the accompanying data points
when favoring composition over inheritance?
-
Write a JUnit theory for the transitive property for
equals()
.
-
Recall the
equals()
and
hashCode()
discussion in Bloch.
Write a JUnit theory that encodes the consistency
property between equals()
and hashCode()
.
-
Build a toy example that violates the theory.
Fix the toy example so that the theory is no longer violated.
-
Consider the
Comparable
interface:
what properties should be checked with theories?