Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

Re: [jmock-user] Mocking FileChannel

Steve Freeman

2008-04-25

Replies: Find Java Web Hosting

Author LoginPost Reply
think about writing that interface from the point of view of its
client, not its implementation.

S.

On 25 Apr 2008, at 05:32, william1104 wrote:
> Hi Nat,
>
> Thanks for your suggestion. I will wrap the FileChannel with an tiny
> interface for the testing.
>
> Thanks and regards,
> William
>
>
>
> Nat Pryce wrote:
>>
>> 2008/4/23 william1104 <william1104@(protected)>:
>>> The mock object is created with "newInstance()" method. That means
>>> the
>>> default constructor of the target class -
>>> "AbstractInterruptibleChannel()"
>>> is not called, the the mock object is not in a "good" state for use.
>>
>> Actually, the problem is that AbstractInterruptibleChannel.close is
>> final and so cannot be mocked.
>>
>>> I will appreciate if anyone can provide a suggestion on how to
>>> handle
>>> this
>>> scenario.
>>
>> If you care about the internal state of an object, mock objects are
>> not the right tool for the job.
>>
>> If the class has final methods, jMock cannot mock it. You could
>> instead introduce an interface between your code and the third-party,
>> mock-unfriendly code. You can mock that interface in the tests of
>> your
>> code. The real implementation will be a thin wrapper around the
>> third-party code and can be tested in integration tests or by your
>> end-to-end tests.
>>
>> --Nat
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Mocking-FileChannel-tp16834671p16889173.html
> Sent from the jMock - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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


©2008 gg3721.com - Jax Systems, LLC, U.S.A.