1 25 package org.archive.io; 26 27 import java.io.ByteArrayInputStream ; 28 import java.util.logging.Level ; 29 import java.util.logging.LogManager ; 30 import java.util.logging.Logger ; 31 32 import junit.framework.TestCase; 33 34 public class SinkHandlerTest extends TestCase { 35 private static final Logger LOGGER = 36 Logger.getLogger(SinkHandlerTest.class.getName()); 37 38 protected void setUp() throws Exception { 39 super.setUp(); 40 String logConfig = "handlers = " + 41 "org.archive.io.SinkHandler\n" + 42 "org.archive.io.SinkHandler.level = ALL"; 43 ByteArrayInputStream bais = 44 new ByteArrayInputStream (logConfig.getBytes()); 45 LogManager.getLogManager().readConfiguration(bais); 46 } 47 48 public void testLogging() throws Exception { 49 LOGGER.severe("Test1"); 50 LOGGER.severe("Test2"); 51 LOGGER.warning("Test3"); 52 RuntimeException e = new RuntimeException ("Nothing exception"); 53 LOGGER.log(Level.SEVERE, "with exception", e); 54 SinkHandler h = SinkHandler.getInstance(); 55 assertEquals(h.getAllUnread().size(), 4); 56 SinkHandlerLogRecord shlr = h.get(3); 57 h.remove(3); 58 assertEquals(h.getAllUnread().size(), 3); 59 h.publish(shlr); 60 assertEquals(h.getAllUnread().size(), 4); 61 } 62 71 } 72 | Popular Tags |