As an example, I have a set of classes that model data metrics. A metric contains a set of
data points, where each data point represents an individual sample, such as the size of the
heap at a given time. I purposely do not list the code for the metric or data point classes; rather,
I list the JUnit tests. Recall that according to one of the tenets of Extreme Programming, we
write test cases before writing code. Listing 1 shows the test case for the Metric class, and
Listing 2 shows the test case for the DataPoint class.

In Listing 1, you can see that the DataPoint class, in addition to maintaining the observed
value for a point in time, supports minimum and maximum values for the time period, computes
the range, and supports scaling and adding data points. The sample test case creates a DataPoint
object in the setUp() method and then exercises each piece of functionality.

Listing 2 shows the test case for the Metric class. The Metric class aggregates the
DataPoint objects and provides access to the collective minimum, maximum, average, range,
standard deviation, and variance. In the setUp() method, the test creates a set of data points
and builds the metric to contain them. Each subsequent test case uses this metric and validates
values computed by hand to those computed by the Metric class.