Reputation: 1234
I have a mina client whose connector is a NioSocketConnector. I have written integration tests of this client with real server. However, I could not find a way to do unit tests. For example, I want to test my custom decoder and encoder works correctly without opening a real socket. And, I want to test my messages are queued correctly in the buffer etc.
I found a DummySession class for testings but I am not sure if this class is enough for a complete unit testing of the client.
Mina suggests unit testing is easy with it so I really wonder how can I do this. Please help with your ideas or links to sample code.
Thanks in advance.
Upvotes: 4
Views: 1087
Reputation: 1234
Unit testing of encoder:
YourEncoder encoder = new YourEncoder();
ProtocolCodecSession session = new ProtocolCodecSession();
encoder.encode(session, message, session.getEncoderOutput());
// encoded message will be in session.getEncoderOutputQueue()
Unit testing of decoder:
//Prepare an IoBuffer which will be decoded, say buf
YourDecoder decoder = new YourDecoder();
ProtocolCodecSession session = new ProtocolCodecSession();
decoder.decode(session, buf, session.getDecoderOutput());
//decoded message will be in session.getDecoderOutputQueue()
Upvotes: 8