1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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(4, h.getAllUnread().size());
56
57
58 SinkHandlerLogRecord shlr = h.getAllUnread().get(3);
59 h.remove(shlr.getSequenceNumber());
60 assertEquals(3, h.getAllUnread().size());
61 h.publish(shlr);
62 assertEquals(4, h.getAllUnread().size());
63 }
64
65
66
67
68
69
70
71
72
73 }