@Test public void writeTest() throws Exception {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    RecordWriter writer = new RecordWriter(out);
    // Generate some log messages and write them
    int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        int n = writer.write(createMessage("This is log message " + i));
        assertTrue(n > 0);
    }
    byte[] data = out.toByteArray();
    ByteArrayInputStream inp = new ByteArrayInputStream(data);
    Timber.LogEvent ev = null;
    int count = 0;
    do {
        ev = Timber.LogEvent.parseDelimitedFrom(inp);
        if (null != ev) {
            count++;
            assertEquals("T", ev.getType());
        }
    } while (null != ev);
    assertEquals(numMessages, count);
}