Added test cases for the logging package

This commit is contained in:
Trustin Lee 2008-08-25 11:02:30 +00:00
parent f22f07ec51
commit 9dabeb4e47
11 changed files with 1399 additions and 0 deletions

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class CommonsLoggerFactoryTest {
@Test
public void testCreation() {
InternalLogger logger = new CommonsLoggerFactory().newInstance("foo");
assertTrue(logger instanceof CommonsLogger);
assertEquals("foo", logger.toString());
}
}

View File

@ -0,0 +1,196 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class CommonsLoggerTest {
private static final Exception e = new Exception();
@Test
public void testIsDebugEnabled() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
expect(mock.isDebugEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
public void testIsInfoEnabled() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
expect(mock.isInfoEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
expect(mock.isWarnEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
expect(mock.isErrorEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.debug("a");
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.debug("a", e);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.info("a");
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.info("a", e);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.warn("a");
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.warn("a", e);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.error("a");
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
org.apache.commons.logging.Log mock =
createStrictMock(org.apache.commons.logging.Log.class);
mock.error("a", e);
replay(mock);
InternalLogger logger = new CommonsLogger(mock, "foo");
logger.error("a", e);
verify(mock);
}
}

View File

@ -0,0 +1,192 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class InternalLoggerFactoryTest {
private static final Exception e = new Exception();
private InternalLoggerFactory oldLoggerFactory;
private InternalLogger mock;
@Before
public void init() {
oldLoggerFactory = InternalLoggerFactory.getDefaultFactory();
InternalLoggerFactory mockFactory = createMock(InternalLoggerFactory.class);
mock = createStrictMock(InternalLogger.class);
expect(mockFactory.newInstance("mock")).andReturn(mock).anyTimes();
replay(mockFactory);
InternalLoggerFactory.setDefaultFactory(mockFactory);
}
@After
public void destroy() {
reset(mock);
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
}
@Test(expected = NullPointerException.class)
public void shouldNotAllowNullDefaultFactory() {
InternalLoggerFactory.setDefaultFactory(null);
}
@Test
public void shouldReturnWrappedLogger() {
assertNotSame(mock, InternalLoggerFactory.getInstance("mock"));
}
@Test
public void testIsDebugEnabled() {
expect(mock.isDebugEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
public void testIsInfoEnabled() {
expect(mock.isInfoEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
expect(mock.isWarnEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
expect(mock.isErrorEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
mock.debug("a");
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
mock.debug("a", e);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
mock.info("a");
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
mock.info("a", e);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
mock.warn("a");
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
mock.warn("a", e);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
mock.error("a");
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
mock.error("a", e);
replay(mock);
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
logger.error("a", e);
verify(mock);
}
}

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class JBossLoggerFactoryTest {
@Test
public void testCreation() {
InternalLogger logger = new JBossLoggerFactory().newInstance("foo");
assertTrue(logger instanceof JBossLogger);
assertEquals("foo", logger.toString());
}
}

View File

@ -0,0 +1,195 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class JBossLoggerTest {
private static final Exception e = new Exception();
@Test
@SuppressWarnings("deprecation")
public void testIsDebugEnabled() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
expect(mock.isDebugEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
@SuppressWarnings("deprecation")
public void testIsInfoEnabled() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
expect(mock.isInfoEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.debug("a");
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.debug("a", e);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.info("a");
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.info("a", e);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.warn("a");
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.warn("a", e);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.error("a");
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
org.jboss.logging.Logger mock =
createStrictMock(org.jboss.logging.Logger.class);
mock.error("a", e);
replay(mock);
InternalLogger logger = new JBossLogger(mock);
logger.error("a", e);
verify(mock);
}
}

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class JdkLoggerFactoryTest {
@Test
public void testCreation() {
InternalLogger logger = new JdkLoggerFactory().newInstance("foo");
assertTrue(logger instanceof JdkLogger);
assertEquals("foo", logger.toString());
}
}

View File

@ -0,0 +1,200 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import java.util.logging.Level;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class JdkLoggerTest {
private static final Exception e = new Exception();
@Test
public void testIsDebugEnabled() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
expect(mock.isLoggable(Level.FINE)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
public void testIsInfoEnabled() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
expect(mock.isLoggable(Level.INFO)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
expect(mock.isLoggable(Level.WARNING)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
expect(mock.isLoggable(Level.SEVERE)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.FINE, "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.FINE, "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.INFO, "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.INFO, "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.WARNING, "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.WARNING, "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.SEVERE, "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.SEVERE, "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
logger.error("a", e);
verify(mock);
}
}

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class Log4JLoggerFactoryTest {
@Test
public void testCreation() {
InternalLogger logger = new Log4JLoggerFactory().newInstance("foo");
assertTrue(logger instanceof Log4JLogger);
assertEquals("foo", logger.toString());
}
}

View File

@ -0,0 +1,195 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class Log4JLoggerTest {
private static final Exception e = new Exception();
@Test
public void testIsDebugEnabled() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
expect(mock.isDebugEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
public void testIsInfoEnabled() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
expect(mock.isInfoEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.debug("a");
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.debug("a", e);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.info("a");
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.info("a", e);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.warn("a");
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.warn("a", e);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.error("a");
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
org.apache.log4j.Logger mock =
createStrictMock(org.apache.log4j.Logger.class);
mock.error("a", e);
replay(mock);
InternalLogger logger = new Log4JLogger(mock);
logger.error("a", e);
verify(mock);
}
}

View File

@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class Slf4JLoggerFactoryTest {
@Test
public void testCreation() {
InternalLogger logger = new Slf4JLoggerFactory().newInstance("foo");
assertTrue(logger instanceof Slf4JLogger);
assertEquals("foo", logger.toString());
}
}

View File

@ -0,0 +1,196 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.logging;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class Slf4JLoggerTest {
private static final Exception e = new Exception();
@Test
public void testIsDebugEnabled() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
expect(mock.isDebugEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@Test
public void testIsInfoEnabled() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
expect(mock.isInfoEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@Test
public void testIsWarnEnabled() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
expect(mock.isWarnEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@Test
public void testIsErrorEnabled() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
expect(mock.isErrorEnabled()).andReturn(true);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@Test
public void testDebug() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.debug("a");
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.debug("a");
verify(mock);
}
@Test
public void testDebugWithException() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.debug("a", e);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.debug("a", e);
verify(mock);
}
@Test
public void testInfo() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.info("a");
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.info("a");
verify(mock);
}
@Test
public void testInfoWithException() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.info("a", e);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.info("a", e);
verify(mock);
}
@Test
public void testWarn() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.warn("a");
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.warn("a");
verify(mock);
}
@Test
public void testWarnWithException() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.warn("a", e);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.warn("a", e);
verify(mock);
}
@Test
public void testError() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.error("a");
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.error("a");
verify(mock);
}
@Test
public void testErrorWithException() {
org.slf4j.Logger mock =
createStrictMock(org.slf4j.Logger.class);
mock.error("a", e);
replay(mock);
InternalLogger logger = new Slf4JLogger(mock);
logger.error("a", e);
verify(mock);
}
}