KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > LoggingTestCaseHid


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.loaders;
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.PrintStream JavaDoc;
26 import java.io.StringWriter JavaDoc;
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.LinkedList JavaDoc;
35 import java.util.logging.Handler JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.LogRecord JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import java.util.regex.Pattern JavaDoc;
40 import javax.swing.event.ChangeEvent JavaDoc;
41 import junit.framework.AssertionFailedError;
42 import junit.framework.TestResult;
43 import org.netbeans.junit.Log;
44 import org.netbeans.junit.NbTestCase;
45 import org.openide.ErrorManager;
46 import org.openide.util.Enumerations;
47 import org.openide.util.Lookup;
48 import org.openide.util.lookup.AbstractLookup;
49 import org.openide.util.lookup.InstanceContent;
50 import org.openide.util.lookup.Lookups;
51 import org.openide.util.lookup.ProxyLookup;
52
53
54 /** Basic skeleton for logging test case.
55  *
56  * @author Jaroslav Tulach
57  */

58 public abstract class LoggingTestCaseHid extends NbTestCase {
59     static {
60         System.setProperty("org.openide.util.Lookup", "org.openide.loaders.LoggingTestCaseHid$Lkp");
61     }
62
63     protected LoggingTestCaseHid (String JavaDoc name) {
64         super (name);
65     }
66     
67     public void run(TestResult result) {
68         Lookup l = Lookup.getDefault();
69         assertEquals("We can run only with our Lookup", Lkp.class, l.getClass());
70         Lkp lkp = (Lkp)l;
71         lkp.reset();
72         
73         super.run(result);
74     }
75     
76     /** Allows subclasses to register content for the lookup. Can be used in
77      * setUp and test methods, after that the content is cleared.
78      * @deprecated Please use {@link org.netbeans.junit.MockServices} instead.
79      */

80     protected final void registerIntoLookup(Object JavaDoc instance) {
81         Lookup l = Lookup.getDefault();
82         assertEquals("We can run only with our Lookup", Lkp.class, l.getClass());
83         Lkp lkp = (Lkp)l;
84         lkp.ic.add(instance);
85     }
86     
87     protected void registerSwitches(String JavaDoc switches, int timeOut) {
88         Log.controlFlow(Logger.getLogger(""), null, switches, timeOut);
89     }
90     
91     //
92
// Our fake lookup
93
//
94
public static final class Lkp extends ProxyLookup {
95         InstanceContent ic;
96         
97         public Lkp () {
98             super(new Lookup[0]);
99         }
100     
101         public void reset() {
102             this.ic = new InstanceContent();
103             AbstractLookup al = new AbstractLookup(ic);
104             setLookups(new Lookup[] { al, Lookups.metaInfServices(getClass().getClassLoader()) });
105         }
106     }
107 }
108
Popular Tags