1 /* Copyright (C) 2009 Egon Willighagen <egonw@users.sf.net> 2 * 3 * Contact: cdk-devel@lists.sourceforge.net 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; either version 2.1 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 package org.openscience.cdk.tools; 20 21 import org.junit.Assert; 22 import org.junit.Test; 23 24 /** 25 * @cdk.module test-core 26 */ 27 public class LoggingToolFactoryTest { 28 29 @Test testSetGetLoggingToolClass()30 public void testSetGetLoggingToolClass() { 31 Class<? extends ILoggingTool> logger = LoggingTool.class; 32 LoggingToolFactory.setLoggingToolClass(logger); 33 Assert.assertEquals(LoggingTool.class.getName(), LoggingToolFactory.getLoggingToolClass().getName()); 34 } 35 36 @Test testCreateLoggingTool()37 public void testCreateLoggingTool() { 38 ILoggingTool logger = LoggingToolFactory.createLoggingTool(LoggingToolFactoryTest.class); 39 Assert.assertNotNull(logger); 40 } 41 42 @Test testCreateLog4jLoggingTool()43 public void testCreateLog4jLoggingTool() { 44 Class<? extends ILoggingTool> logger = LoggingTool.class; 45 LoggingToolFactory.setLoggingToolClass(logger); 46 ILoggingTool instance = LoggingToolFactory.createLoggingTool(LoggingToolFactoryTest.class); 47 Assert.assertTrue(instance instanceof LoggingTool); 48 } 49 50 @Test testCustomLogger()51 public void testCustomLogger() { 52 LoggingToolFactory.setLoggingToolClass(CustomLogger.class); 53 ILoggingTool instance = LoggingToolFactory.createLoggingTool(LoggingToolFactoryTest.class); 54 Assert.assertTrue(instance instanceof CustomLogger); 55 } 56 57 /** 58 * Custom dummy logger used in the 59 * {@link LoggingToolFactoryTest#testCustomLogger()} test to see if 60 * the custom {@link ILoggingTool} is really being used. It does 61 * not really implement any method, as the test uses a mere 62 * <code>instanceof</code> call. 63 */ 64 private static class CustomLogger implements ILoggingTool { 65 CustomLogger(Class<?> sourceClass)66 private CustomLogger(Class<?> sourceClass) {} 67 create(Class<?> sourceClass)68 public static ILoggingTool create(Class<?> sourceClass) { 69 return new CustomLogger(sourceClass); 70 } 71 72 @Override debug(Object object)73 public void debug(Object object) {} 74 75 @Override debug(Object object, Object... objects)76 public void debug(Object object, Object... objects) {} 77 78 @Override dumpClasspath()79 public void dumpClasspath() {} 80 81 @Override dumpSystemProperties()82 public void dumpSystemProperties() {} 83 84 @Override error(Object object)85 public void error(Object object) {} 86 87 @Override error(Object object, Object... objects)88 public void error(Object object, Object... objects) {} 89 90 @Override fatal(Object object)91 public void fatal(Object object) {} 92 93 @Override info(Object object)94 public void info(Object object) {} 95 96 @Override info(Object object, Object... objects)97 public void info(Object object, Object... objects) {} 98 99 @Override isDebugEnabled()100 public boolean isDebugEnabled() { 101 return true; 102 } 103 104 @Override setStackLength(int length)105 public void setStackLength(int length) {} 106 107 @Override warn(Object object)108 public void warn(Object object) {} 109 110 @Override warn(Object object, Object... objects)111 public void warn(Object object, Object... objects) {} 112 113 @Override setLevel(int level)114 public void setLevel(int level) { 115 116 } 117 118 @Override getLevel()119 public int getLevel() { 120 return 0; 121 } 122 } 123 } 124