/*
 * Created on 13-Apr-2005
 */
package org.bodington.logging;

import junit.framework.TestCase;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;

/**
 * @author buckett
 */
public class SimpleThrowableLayoutTest extends TestCase
{

    /*
     * Class under test for String format(LoggingEvent)
     */
    public void testFormatLoggingEvent()
    {
        SimpleThrowableLayout layout = new SimpleThrowableLayout();

        LoggingEvent event = new LoggingEvent(this.getName(), Logger.getRootLogger(), Level.INFO,"@@Log Message@@",null);
        String output = layout.format(event);
        
        assertTrue(output.indexOf("@@Test Message@@") == -1);
        assertTrue(output.indexOf("@@Log Message@@") > 0);

        Throwable throwable = new Throwable("@@Test Message@@");
        event = new LoggingEvent(this.getName(), Logger.getRootLogger(), Level.INFO,"@@Log Message@@",throwable);
        output = layout.format(event);
        
        assertTrue(output.indexOf("@@Test Message@@") > 0);
        assertTrue(output.indexOf("@@Log Message@@") > 0);
    }

    public void testThrowableFormat()
    {
        SimpleThrowableLayout layout = new SimpleThrowableLayout();
        Throwable throwable = new Throwable("@@Test Message@@");
        StringBuffer output = new StringBuffer();
        layout.throwableFormat(output, throwable);
        
        assertTrue(output.indexOf("@@Test Message@@") > 0);
        assertTrue(output.indexOf("testThrowableFormat") > 0);
    }

}
