1 16 package org.apache.cocoon.util.test; 17 18 import junit.framework.TestCase; 19 20 import org.apache.avalon.framework.logger.ConsoleLogger; 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.cocoon.util.Deprecation; 23 import org.apache.cocoon.util.DeprecationException; 24 25 31 public class DeprecationTestCase extends TestCase { 32 public DeprecationTestCase(String name) { 33 super(name); 34 } 35 36 private Logger originalLogger; 37 private Logger consoleLogger; 38 39 public void setUp() throws Exception { 40 super.setUp(); 41 originalLogger = Deprecation.logger; 42 consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED); 45 Deprecation.setLogger(consoleLogger); 46 Deprecation.setForbiddenLevel(Deprecation.ERROR); 47 } 48 49 public void tearDown() throws Exception { 50 Deprecation.setLogger(originalLogger); 51 super.tearDown(); 52 } 53 54 public void testPrecond() { 55 assertFalse(consoleLogger.isInfoEnabled()); 58 assertFalse(consoleLogger.isWarnEnabled()); 59 assertFalse(consoleLogger.isErrorEnabled()); 60 } 61 62 public void testInfoOk() { 63 try { 64 Deprecation.logger.info("testing deprecation logs"); 65 } catch(DeprecationException de) { 66 fail("Should not throw an exception"); 67 } 68 } 69 70 public void testWarnOk() { 71 try { 72 Deprecation.logger.warn("testing deprecation logs"); 73 } catch(DeprecationException de) { 74 fail("Should not throw an exception"); 75 } 76 } 77 78 public void testErrorFails() { 79 try { 80 Deprecation.logger.error("testing deprecation logs"); 81 } catch(DeprecationException de) { 82 return; } 84 fail("Should throw an exception"); 85 } 86 87 public void testDebugFails() { 88 Deprecation.setForbiddenLevel(Deprecation.DEBUG); 89 try { 90 Deprecation.logger.debug("testing deprecation logs"); 91 } catch(DeprecationException de) { 92 return; } 94 fail("Should throw an exception"); 95 } 96 97 public void testInfoDisabled() { 98 assertFalse(Deprecation.logger.isInfoEnabled()); 99 } 100 101 public void testWarnDisabled() { 102 assertFalse(Deprecation.logger.isWarnEnabled()); 103 } 104 105 public void testErrorEnabled() { 106 assertTrue(Deprecation.logger.isErrorEnabled()); 107 } 108 } 109 | Popular Tags |