1 19 20 package org.openide.loaders; 21 import java.beans.PropertyChangeEvent ; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.PrintStream ; 26 import java.io.StringWriter ; 27 import java.lang.reflect.InvocationTargetException ; 28 import java.lang.reflect.InvocationTargetException ; 29 import java.net.URL ; 30 import java.util.ArrayList ; 31 import java.util.Date ; 32 import java.util.Enumeration ; 33 import java.util.HashMap ; 34 import java.util.LinkedList ; 35 import java.util.logging.Handler ; 36 import java.util.logging.Level ; 37 import java.util.logging.LogRecord ; 38 import java.util.logging.Logger ; 39 import java.util.regex.Pattern ; 40 import javax.swing.event.ChangeEvent ; 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 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 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 80 protected final void registerIntoLookup(Object 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 switches, int timeOut) { 88 Log.controlFlow(Logger.getLogger(""), null, switches, timeOut); 89 } 90 91 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 |