<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Test Driven log4j Logging Code Example</title>
	<atom:link href="http://jawspeak.com/2009/06/21/test-driven-log4j-logging-code-example/feed/" rel="self" type="application/rss+xml" />
	<link>http://jawspeak.com/2009/06/21/test-driven-log4j-logging-code-example/</link>
	<description>Jonathan Andrew Wolter</description>
	<lastBuildDate>Sun, 13 May 2012 19:46:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Grunx</title>
		<link>http://jawspeak.com/2009/06/21/test-driven-log4j-logging-code-example/comment-page-1/#comment-2449</link>
		<dc:creator>Grunx</dc:creator>
		<pubDate>Wed, 03 Aug 2011 19:01:03 +0000</pubDate>
		<guid isPermaLink="false">http://jawspeak.com/?p=96#comment-2449</guid>
		<description>Hi guys,

Since your comments where excellent pointers.
Let me share the following snippet:

...
  private Appender mockAppender;

  @Before
  public void setupMocksAndTestee() {
    mockAppender = Mockito.mock(AppenderSkeleton.class);
    Logger logger = Logger.getLogger(testee.getClass());
    logger.addAppender(mockAppender);
    logger.setLevel(Level.INFO);
  }

  @Test
  public void infoLogEventReceived() {
    testee.doSomething();
    
    ArgumentCaptor loggingEventCaptor = ArgumentCaptor.forClass(LoggingEvent.class);
    verify(mockAppender).doAppend(loggingEventCaptor.capture());
    
    LoggingEvent loggingEvent = loggingEventCaptor.getValue();
    assertEquals(&quot;Expected info log message.&quot;, loggingEvent.getRenderedMessage());
    assertEquals(Level.INFO, loggingEvent.getLevel());
  }
...</description>
		<content:encoded><![CDATA[<p>Hi guys,</p>
<p>Since your comments where excellent pointers.<br />
Let me share the following snippet:</p>
<p>&#8230;<br />
  private Appender mockAppender;</p>
<p>  @Before<br />
  public void setupMocksAndTestee() {<br />
    mockAppender = Mockito.mock(AppenderSkeleton.class);<br />
    Logger logger = Logger.getLogger(testee.getClass());<br />
    logger.addAppender(mockAppender);<br />
    logger.setLevel(Level.INFO);<br />
  }</p>
<p>  @Test<br />
  public void infoLogEventReceived() {<br />
    testee.doSomething();</p>
<p>    ArgumentCaptor loggingEventCaptor = ArgumentCaptor.forClass(LoggingEvent.class);<br />
    verify(mockAppender).doAppend(loggingEventCaptor.capture());</p>
<p>    LoggingEvent loggingEvent = loggingEventCaptor.getValue();<br />
    assertEquals(&#8220;Expected info log message.&#8221;, loggingEvent.getRenderedMessage());<br />
    assertEquals(Level.INFO, loggingEvent.getLevel());<br />
  }<br />
&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://jawspeak.com/2009/06/21/test-driven-log4j-logging-code-example/comment-page-1/#comment-1306</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Sun, 20 Dec 2009 16:20:36 +0000</pubDate>
		<guid isPermaLink="false">http://jawspeak.com/?p=96#comment-1306</guid>
		<description>I was doing this trick first in a codebase that didn&#039;t have mockito. (Thus mocking was more verbose, and less friendly).

Pre-Mockito, I avoided Mocks and built my own test doubles where I could. This way I didn&#039;t have my tests tied to the api-calls of the mocked object, but just made assertions-about-state. This generally meant one up front cost to build the test double (i.e. this one, or an InMemoryRepository, etc.), and then very small incremental costs to use this new test collaborator.

I still do this in Post-Mockito codebases. Recently I was writing some classpath repository mocking code. It was verbose, and required repeating frequently as boilerplate everywhere I wanted to set up this mock test double. Even when refactored into a parametrized method call, I didn&#039;t like it. Too hard to see the important interactions in my test. So I re-wrote a test double that I only could make state assertions on at the end. Much better, imho.</description>
		<content:encoded><![CDATA[<p>I was doing this trick first in a codebase that didn&#8217;t have mockito. (Thus mocking was more verbose, and less friendly).</p>
<p>Pre-Mockito, I avoided Mocks and built my own test doubles where I could. This way I didn&#8217;t have my tests tied to the api-calls of the mocked object, but just made assertions-about-state. This generally meant one up front cost to build the test double (i.e. this one, or an InMemoryRepository, etc.), and then very small incremental costs to use this new test collaborator.</p>
<p>I still do this in Post-Mockito codebases. Recently I was writing some classpath repository mocking code. It was verbose, and required repeating frequently as boilerplate everywhere I wanted to set up this mock test double. Even when refactored into a parametrized method call, I didn&#8217;t like it. Too hard to see the important interactions in my test. So I re-wrote a test double that I only could make state assertions on at the end. Much better, imho.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lucas</title>
		<link>http://jawspeak.com/2009/06/21/test-driven-log4j-logging-code-example/comment-page-1/#comment-1305</link>
		<dc:creator>lucas</dc:creator>
		<pubDate>Sun, 20 Dec 2009 12:58:28 +0000</pubDate>
		<guid isPermaLink="false">http://jawspeak.com/?p=96#comment-1305</guid>
		<description>hi,

I wonder, why you just didn&#039;t mock the logger. Afterwards you would check whether some collaborations appeared, Mockito.verify(mockLogger).info(Session Size for session id:  + sessionId +  (approx. total  + (7 + 3 + 1 + 4 + 1) +  bytes)). I do like this when I have to test some logging. Can you provide cons &amp; prons in those two approaches?

cheers</description>
		<content:encoded><![CDATA[<p>hi,</p>
<p>I wonder, why you just didn&#8217;t mock the logger. Afterwards you would check whether some collaborations appeared, Mockito.verify(mockLogger).info(Session Size for session id:  + sessionId +  (approx. total  + (7 + 3 + 1 + 4 + 1) +  bytes)). I do like this when I have to test some logging. Can you provide cons &amp; prons in those two approaches?</p>
<p>cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>

