Skip to content

Instantly share code, notes, and snippets.

@coderunner
Created September 12, 2011 17:04
Show Gist options
  • Select an option

  • Save coderunner/1211780 to your computer and use it in GitHub Desktop.

Select an option

Save coderunner/1211780 to your computer and use it in GitHub Desktop.
test stream logger
public class TestStreamLogger
{
private static final String LOGGER_NAME = "logger_name";
private static final Level LEVEL = Level.INFO;
private static final String MESSAGE = "message";
private StreamLogger logger;
private OutputStream stream;
@Before
public void setup()
{
stream = mock(OutputStream.class);
logger = new StreamLogger(LOGGER_NAME, stream);
}
@Test
public void shouldWriteFormattedMesssageToStream() throws Exception
{
logger.log(Level.INFO, MESSAGE);
verify(stream).write((LOGGER_NAME +" - " + LEVEL + " : " + MESSAGE).getBytes());
}
@Test
public void shouldCloseStream() throws Exception
{
logger.close();
verify(stream).close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment