1 // Tags: JDK1.4 |
|
2 // Uses: TestFilter TestSecurityManager TestResourceBundle |
|
3 |
|
4 // Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 package gnu.testlet.java.util.logging.Logger; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 import java.util.logging.Level; |
|
29 import java.util.logging.Logger; |
|
30 import java.util.logging.Formatter; |
|
31 import java.util.logging.SimpleFormatter; |
|
32 |
|
33 import java.util.MissingResourceException; |
|
34 |
|
35 |
|
36 /** |
|
37 * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> |
|
38 */ |
|
39 public class getAnonymousLogger |
|
40 implements Testlet |
|
41 { |
|
42 TestSecurityManager sec = new TestSecurityManager(); |
|
43 |
|
44 public void test(TestHarness th) |
|
45 { |
|
46 Logger al; |
|
47 Throwable caught; |
|
48 TestFilter filter = new TestFilter(); |
|
49 Formatter formatter = new SimpleFormatter(); |
|
50 |
|
51 try |
|
52 { |
|
53 sec.install(); |
|
54 // This used to be 'sec.setGrantLoggingControl(false)', but that |
|
55 // causes Logger.getAnonymousLogger() to fail on JDK 1.4.2. |
|
56 // Stephen Crawley: 2004-05-11 |
|
57 sec.setGrantLoggingControl(true); |
|
58 |
|
59 // Check #1. |
|
60 al = Logger.getAnonymousLogger(); |
|
61 th.check(al != null); |
|
62 |
|
63 // Check #2: New instance for each call. |
|
64 th.check(al != Logger.getAnonymousLogger()); |
|
65 |
|
66 // Check #3. |
|
67 al = Logger.getAnonymousLogger(); |
|
68 th.check(al.getName(), null); |
|
69 |
|
70 // Check #4. |
|
71 th.check(al.getResourceBundle(), null); |
|
72 |
|
73 // Check #5. |
|
74 th.check(al.getResourceBundleName(), null); |
|
75 |
|
76 // Check #6: Parent is root logger. |
|
77 th.check(al.getParent(), Logger.getLogger("")); |
|
78 |
|
79 // Check #7. |
|
80 al.setFilter(filter); |
|
81 al.setUseParentHandlers(false); |
|
82 al.setLevel(Level.FINEST); |
|
83 al.entering("Class", "method", "txt"); |
|
84 th.check(formatter.formatMessage(filter.getLastRecord()), "ENTRY txt"); |
|
85 |
|
86 // Check #8. |
|
87 al = Logger.getAnonymousLogger(TestResourceBundle.class.getName()); |
|
88 th.check(al.getResourceBundle() instanceof TestResourceBundle); |
|
89 |
|
90 // Check #9. |
|
91 al.setFilter(filter); |
|
92 al.setUseParentHandlers(false); |
|
93 al.setLevel(Level.FINEST); |
|
94 al.entering("Class", "method", "txt"); |
|
95 th.check(formatter.formatMessage(filter.getLastRecord()), "BETRETEN txt"); |
|
96 |
|
97 // Check #10. |
|
98 try |
|
99 { |
|
100 Logger.getAnonymousLogger("garbageClassName"); |
|
101 th.check(false); |
|
102 } |
|
103 catch (MissingResourceException ex) |
|
104 { |
|
105 th.check(true); |
|
106 } |
|
107 catch (Exception ex) |
|
108 { |
|
109 th.check(false); |
|
110 th.debug(ex); |
|
111 } |
|
112 } |
|
113 finally |
|
114 { |
|
115 sec.uninstall(); |
|
116 } |
|
117 } |
|
118 } |
|