You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Serkan Demir <se...@oksijen.com> on 2006/04/14 12:15:40 UTC

Need a concrete or mock class of Protocol Session for tests

Hi guys,

I have implemented a protocol stack with MINA. Now, I have to increase 
my unit tests coverage. I have stuck at the testing of my 
ProtocolHandler's methods (sessionCreated,sessionOpened, sessionClosed 
etc..) Therefore i need a concrete or mock class of Protocol Session for 
my tests. I noticed the TestSession class in your codebase, but it is 
private class like as ProtocolSessionImpl. Is there any session factory 
or a public concrete class of ProtocolSession which I can use for tests? 
If your answer is no, i will pass to my second alternative, JMock.

I am talking about unit tests of such method.Unless i create a session 
in unit test scope, i cannot test its functionality. Could you recommend 
a way for testing such methods?

    public void messageReceived(ProtocolSession session, Object message) {
        if (BaseStackLogger.logger.isDebugEnabled()){
            BaseStackLogger.logger.debug("Message is received. Message 
is:"+message.toString());
        }

 // some other actions have been done
//
//
     if(!message instanceof MyMessageType) {
    session.close();
    }
     resetTimer();
    }

Re: Need a concrete or mock class of Protocol Session for tests

Posted by Vinod Panicker <vi...@gmail.com>.
Hi,

>From what I've seen, mock objects are fantastic - but use them only as
a last resort.  If possible break up your functionality in a way that
you can call it from your unit test without mocking any objects.

If you do go and create a mock object of ProtocolSession, then I'd
advise you to do so against a final MINA release so that you dont have
to keep changing the recorded method calls.

I believe MINA uses easymock for mock objects.

HTH,
Vinod.

On 4/14/06, Serkan Demir <se...@oksijen.com> wrote:
> Hi guys,
>
> I have implemented a protocol stack with MINA. Now, I have to increase
> my unit tests coverage. I have stuck at the testing of my
> ProtocolHandler's methods (sessionCreated,sessionOpened, sessionClosed
> etc..) Therefore i need a concrete or mock class of Protocol Session for
> my tests. I noticed the TestSession class in your codebase, but it is
> private class like as ProtocolSessionImpl. Is there any session factory
> or a public concrete class of ProtocolSession which I can use for tests?
> If your answer is no, i will pass to my second alternative, JMock.
>
> I am talking about unit tests of such method.Unless i create a session
> in unit test scope, i cannot test its functionality. Could you recommend
> a way for testing such methods?
>
>     public void messageReceived(ProtocolSession session, Object message) {
>         if (BaseStackLogger.logger.isDebugEnabled()){
>             BaseStackLogger.logger.debug("Message is received. Message
> is:"+message.toString());
>         }
>
>  // some other actions have been done
> //
> //
>      if(!message instanceof MyMessageType) {
>     session.close();
>     }
>      resetTimer();
>     }
>