« Return to Thread: How would you test this?

How would you test this?

by Louis Rose-2 :: Rate this Message:

Reply to Author | View in Thread

Hi all,

I'm new to jMock, and am exploring the limits of what it can and can't
do. I've recently discovered a pattern that I'm struggling to test with
jMock. I'll present an example, and I hope you can show me how you'd
test this. I suspect I need to adjust my approach to use jMock in this
situation. Thanks in advance!

Suppose we have a TrackImpl class, which has an attribute, circuit of
type List<Point>. Point has a subclass, SpeedPoint. We wish to add a
method to Track, getPreviousSpeedPoint(Point current). The new method will:

- return the nearest previous SpeedPoint in circuit to the given parameter.
- wrap around to find the nearest previous SpeedPoint. (For example,
current could be at index 0, and a SpeedPoint at index circuit.size() -
1. In that case, the SpeedPoint at circuit.size() - 1 should be returned).
- return null if no SpeedPoints are found in circuit.
- throw an IllegalArgumentException if current is not contained in circuit.

I hope this explanation is clear! I'd be interested in seeing your tests
for the first couple of bullet points.

I feel like I should be stubbing out Track#getCircuit() by subclassing
TrackImpl. Is a different approach used with jMock?

Many thanks in advance.

Cheers,
Louis.

----
Louis Rose
Research Student
Department of Computer Science,
University of York,
Heslington, York, YO10 5DD, United Kingdom.
+44 1904 434762
Twitter: @louismrose

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: How would you test this?