yoavs 2003/06/06 19:56:55
Added: tests/src/java/org/apache/log4j/filter
ThrowableClassMatchFilterTestCase.java
Log:
- Initial version of ThrowableClassMatchFilterTestCase
Revision Changes Path
1.1
jakarta-log4j-sandbox/tests/src/java/org/apache/log4j/filter/ThrowableClassMatchFilterTestCase.java
Index: ThrowableClassMatchFilterTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*/
package org.apache.log4j.filter;
import java.io.IOException;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.filter.ThrowableClassMatchFilter;
import org.apache.log4j.spi.LoggingEvent;
/**
* Test case for ThrowableClassMatchFilter.java.
*
* @author Yoav Shapira <[EMAIL PROTECTED]>
* @since 1.3
*/
public class ThrowableClassMatchFilterTestCase extends TestCase {
/**
* The root logger.
*/
Logger root;
/**
* Constructor.
*
* @param name The test name
*/
public ThrowableClassMatchFilterTestCase(String name) {
super(name);
}
/**
* Sets up the test.
*/
public void setUp() {
root = Logger.getRootLogger();
}
/**
* Tears down the test.
*/
public void tearDown() {
root.getLoggerRepository().resetConfiguration();
}
/**
* Test 1: create and configure a filter
* for java.lang.Exception and no subclasses.
*
* @throws Exception If an error occurs
*/
public void test1() throws Exception {
ThrowableClassMatchFilter theFilter = new ThrowableClassMatchFilter();
theFilter.setThrowableClass(Exception.class);
theFilter.setIncludeSubclasses(false);
// Create logging event that should match
Exception e = new Exception("Dummy");
LoggingEvent event = new LoggingEvent(getClass().getName(),
root, Level.DEBUG, "Test message", e);
boolean match = theFilter.match(event);
assertTrue(match);
// Create logging event that should not match
IOException ioe = new IOException("Dummy");
LoggingEvent event2 = new LoggingEvent(getClass().getName(),
root, Level.DEBUG, "Test messahe", ioe);
match = theFilter.match(event2);
assertFalse(match);
}
/**
* Test 2: match java.lang.Exception and its subclasses.
*
* @throws Exception if an error occurs
*/
public void test2() throws Exception {
ThrowableClassMatchFilter theFilter = new ThrowableClassMatchFilter();
theFilter.setThrowableClass(Exception.class);
theFilter.setIncludeSubclasses(true);
// Create logging event that should match.
Exception e = new Exception("Dummy");
LoggingEvent event = new LoggingEvent(getClass().getName(),
root, Level.DEBUG, "Test message", e);
boolean match = theFilter.match(event);
assertTrue(match);
// Create another one that should match
IOException ioe = new IOException("Dummy");
LoggingEvent event2 = new LoggingEvent(getClass().getName(),
root, Level.DEBUG, "Test message", ioe);
match = theFilter.match(event);
assertTrue(match);
}
/**
* Creates the test suite.
*
* @return The test suite
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ThrowableClassMatchFilterTestCase("test1"));
suite.addTest(new ThrowableClassMatchFilterTestCase("test2"));
return suite;
}
}
// End of class: ThrowableClassMatchFilterTestCase.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]