<p>I haven&#39;t done it myself, but you could try using powermock to mock LoggerFactory to provide another mock that specifies what you want to log.</p>
<p>Nik</p>
<p><blockquote type="cite">On Apr 28, 2010 2:16 PM, &quot;Chris Helck&quot; &lt;<a href="mailto:Chris.Helck@us.icap.com">Chris.Helck@us.icap.com</a>&gt; wrote:<br><br>






<div>


<p><font size="2" face="Arial">I want to unit test some objects and to check that the objects are logging certain messages under certain cirmcumstances. Is this possible? Is it easy?</font></p>

<p><font size="2" face="Arial">I am using slf4j. When I run the unit tests I use the NOP logger, in production we use logback. </font>
</p>

<p><font size="2" face="Arial">I want something like:</font>
</p>

<p><font size="2" face="Arial">  Logger logger = LoggerFactory.getLogger(MyStuff.class);</font>

<br><font size="2" face="Arial">  <a href="http://logger.info" target="_blank">logger.info</a>( &quot;Hello World&quot;);</font>
</p>

<p><font size="2" face="Arial">  assertTrue( logger.wasLoggedAsInfo( &quot;Hello World&quot;));</font>
</p>

<p><font size="2" face="Arial">Thanks,</font>

<br><font size="2" face="Arial">C. Helck</font>
</p>
<br>
<br>

<p>        
</p>


<p><span style="font-family:&#39;Arial&#39;;font-size:8pt">**********************************************************************</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt">This communication and all information (including, but not limited to,</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> market prices/levels and data) contained therein (the &quot;Information&quot;) is</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> for informational purposes only, is confidential, may be legally</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> privileged and is the intellectual property of ICAP plc and its affiliates</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> (&quot;ICAP&quot;) or third parties. No confidentiality or privilege is waived or</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> lost by any mistransmission. The Information is not, and should not</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> be construed as, an offer, bid or solicitation in relation to any</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> financial instrument or as an official confirmation of any transaction.</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> The Information is not warranted, including, but not limited, as to</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> completeness, timeliness or accuracy and is subject to change</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> without notice. ICAP assumes no liability for use or misuse of the</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> Information. All representations and warranties are expressly</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> disclaimed. The Information does not necessarily reflect the views of</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> ICAP. Access to the Information by anyone else other than the</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> recipient is unauthorized and any disclosure, copying, distribution or</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> any action taken or omitted to be taken in reliance on it is prohibited. If</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> you receive this message in error, please immediately delete it and all</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> copies of it from your system, destroy any hard copies of it and</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> notify the sender.</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt">**********************************************************************</span></p>
<p><span style="font-family:&#39;Arial&#39;;font-size:8pt"> </span></p></div>

<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://qos.ch/mailman/listinfo/logback-user" target="_blank">http://qos.ch/mailman/listinfo/logback-user</a><br>
<br></blockquote></p>