/** Method: response(byte[] buffer) */
  public void testResponse() throws Exception {
    sequencialRecorder.start();

    final String string1 = "request";
    final String string2 = "new_request";

    sequencialRecorder.response(string1.getBytes());

    sequencialRecorder.response(string2.getBytes());

    sequencialRecorder.messageSent();

    List<Message> messages = sequencialRecorder.getMessages();

    Assert.assertEquals(1, messages.size());

    final Message message = messages.get(0);

    Assert.assertEquals(message.type, MessageType.RESPONSE);

    final byte[] content = message.content;

    String expected = String.format("%s%s", string1, string2);

    final String actual = new String(content);

    Assert.assertEquals(expected, actual);
  }
 /** Method: start() */
 public void testStart() throws Exception {
   Assert.assertNull(sequencialRecorder.getMessages());
   sequencialRecorder.start();
   final List<Message> messages = sequencialRecorder.getMessages();
   Assert.assertNotNull(messages);
   Assert.assertTrue(messages.size() == 0);
 }
  /** Method: stop() */
  public void testStop() throws Exception {
    Assert.assertNull(sequencialRecorder.getMessages());
    sequencialRecorder.start();
    final List<Message> messages = sequencialRecorder.getMessages();

    Assert.assertNotNull(messages);
    Assert.assertTrue(messages.isEmpty());

    sequencialRecorder.stop();

    final List<Message> msgsToAssert = sequencialRecorder.getMessages();
    Assert.assertTrue(msgsToAssert.isEmpty());
  }
  /** Method: getMessages() */
  public void testGetMessagesConversation() throws Exception {
    sequencialRecorder.start();

    final String string1 = "request";
    final String string2 = "new_request";

    final String response1 = "response";
    final String response2 = "new_response";

    sequencialRecorder.request(string1.getBytes());

    sequencialRecorder.request(string2.getBytes());

    sequencialRecorder.response(response1.getBytes());

    sequencialRecorder.response(response2.getBytes());

    List<Message> messages = sequencialRecorder.getMessages();

    Assert.assertEquals(1, messages.size());

    sequencialRecorder.messageSent();

    messages = sequencialRecorder.getMessages();

    Assert.assertEquals(2, messages.size());

    final Message message = messages.get(0);

    final byte[] content = message.content;

    String expected = String.format("%s%s", string1, string2);

    final String actual = new String(content);

    Assert.assertEquals(expected, actual);

    Assert.assertEquals(MessageType.REQUEST, message.type);

    sequencialRecorder.request(string2.getBytes());

    messages = sequencialRecorder.getMessages();

    Assert.assertEquals(2, messages.size());

    sequencialRecorder.response(response1.getBytes());

    messages = sequencialRecorder.getMessages();

    Assert.assertEquals(3, messages.size());

    sequencialRecorder.messageSent();

    messages = sequencialRecorder.getMessages();

    Assert.assertEquals(4, messages.size());
  }