diff --git a/src/test/java/org/jboss/netty/logging/CommonsLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/CommonsLoggerFactoryTest.java new file mode 100644 index 0000000000..46e3b9e391 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/CommonsLoggerFactoryTest.java @@ -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()); + } +} diff --git a/src/test/java/org/jboss/netty/logging/CommonsLoggerTest.java b/src/test/java/org/jboss/netty/logging/CommonsLoggerTest.java new file mode 100644 index 0000000000..8d6380f120 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/CommonsLoggerTest.java @@ -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); + } +} diff --git a/src/test/java/org/jboss/netty/logging/InternalLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/InternalLoggerFactoryTest.java new file mode 100644 index 0000000000..1b686b392f --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/InternalLoggerFactoryTest.java @@ -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); + } +} diff --git a/src/test/java/org/jboss/netty/logging/JBossLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/JBossLoggerFactoryTest.java new file mode 100644 index 0000000000..f3c87b48af --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/JBossLoggerFactoryTest.java @@ -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()); + } +} diff --git a/src/test/java/org/jboss/netty/logging/JBossLoggerTest.java b/src/test/java/org/jboss/netty/logging/JBossLoggerTest.java new file mode 100644 index 0000000000..7950e1f585 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/JBossLoggerTest.java @@ -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); + } +} diff --git a/src/test/java/org/jboss/netty/logging/JdkLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/JdkLoggerFactoryTest.java new file mode 100644 index 0000000000..9801e73564 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/JdkLoggerFactoryTest.java @@ -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()); + } +} diff --git a/src/test/java/org/jboss/netty/logging/JdkLoggerTest.java b/src/test/java/org/jboss/netty/logging/JdkLoggerTest.java new file mode 100644 index 0000000000..8f83c22912 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/JdkLoggerTest.java @@ -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); + } +} diff --git a/src/test/java/org/jboss/netty/logging/Log4JLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/Log4JLoggerFactoryTest.java new file mode 100644 index 0000000000..4d682fc729 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/Log4JLoggerFactoryTest.java @@ -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()); + } +} diff --git a/src/test/java/org/jboss/netty/logging/Log4JLoggerTest.java b/src/test/java/org/jboss/netty/logging/Log4JLoggerTest.java new file mode 100644 index 0000000000..dcaeb731d3 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/Log4JLoggerTest.java @@ -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); + } +} diff --git a/src/test/java/org/jboss/netty/logging/Slf4JLoggerFactoryTest.java b/src/test/java/org/jboss/netty/logging/Slf4JLoggerFactoryTest.java new file mode 100644 index 0000000000..6482f3c8da --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/Slf4JLoggerFactoryTest.java @@ -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()); + } +} diff --git a/src/test/java/org/jboss/netty/logging/Slf4JLoggerTest.java b/src/test/java/org/jboss/netty/logging/Slf4JLoggerTest.java new file mode 100644 index 0000000000..9f23957632 --- /dev/null +++ b/src/test/java/org/jboss/netty/logging/Slf4JLoggerTest.java @@ -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); + } +}