Hi Steve,
Thanks for the insightful question - I can use it in other situations to
determine whether to use a mock.
I agree that, in this case, there doesn't seem to be a collaborating
object. This example wasn't as good as I initially thought, I'm sorry.
I'm still a little confused about whether jMock can be used to stub out
methods on the object under test? I guess not. Does wanting to stub out
a method on the object under test indicate a problem with the design?
I'll post a better example if I stumble across one.
Many thanks for the help.
Cheers,
Louis.
Steve Freeman wrote:
> I don't see what needs to be mocked in this scenario. What is the
> collaborating object that should be replaced?
>
> S.
>
> On 22 May 2009, at 10:23, Louis Rose wrote:
>> 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>>
>>
>
> Steve Freeman
> Winner of the Agile Alliance Gordon Pask award 2006
>
>
http://www.m3p.co.uk>
> M3P Limited.
> Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
> Company registered in England & Wales. Number 03689627
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>
http://xircles.codehaus.org/manage_email>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email