1 19 package org.openide.filesystems; 20 21 import java.net.URL ; 22 import java.net.URLClassLoader ; 23 import java.util.logging.Handler ; 24 import java.util.logging.Level ; 25 import java.util.logging.LogRecord ; 26 import java.util.logging.Logger ; 27 import junit.framework.*; 28 import org.openide.ErrorManager; 29 import java.awt.Component ; 30 import java.awt.Image ; 31 import java.awt.MediaTracker ; 32 import java.awt.Toolkit ; 33 import java.awt.image.BufferedImage ; 34 import java.awt.image.ImageObserver ; 35 import java.lang.ref.*; 36 import java.util.*; 37 38 42 public class MIMESupportResolversTest extends TestCase { 43 static { 44 System.setProperty("org.openide.util.Lookup", "org.openide.filesystems.MIMESupportResolversTest$Lkp"); 45 Logger.getLogger("").addHandler(new ErrMgr()); 46 Logger.getLogger("").setLevel(Level.ALL); 47 } 48 49 50 public MIMESupportResolversTest (String testName) { 51 super (testName); 52 } 53 54 protected void setUp () throws Exception { 55 } 56 57 protected void tearDown () throws Exception { 58 } 59 60 public static Test suite () { 61 TestSuite suite = new TestSuite(MIMESupportResolversTest.class); 62 return suite; 63 } 64 65 66 public void testWrongImplOfGetResolvers() throws Exception { 67 MIMEResolver[] all = MIMESupport.getResolvers(); 68 assertTrue("Error manager race condition activated", ErrMgr.switchDone); 69 assertEquals("there is one", 1, all.length); 70 assertEquals("c1 the original one", Lkp.c1, all[0]); 71 72 all = MIMESupport.getResolvers(); 73 assertEquals("there is one", 1, all.length); 74 assertEquals("c2 the new one", Lkp.c2, all[0]); 75 } 76 77 78 79 public static final class Lkp extends org.openide.util.lookup.AbstractLookup { 80 private ErrMgr err = new ErrMgr(); 81 private org.openide.util.lookup.InstanceContent ic; 82 static MIMEResolver c1 = new MIMEResolver() { 83 public String findMIMEType(FileObject fo) { 84 return null; 85 } 86 87 public String toString() { 88 return "C1"; 89 } 90 }; 91 static MIMEResolver c2 = new MIMEResolver() { 92 public String findMIMEType(FileObject fo) { 93 return null; 94 } 95 public String toString() { 96 return "C2"; 97 } 98 }; 99 100 public Lkp () { 101 this (new org.openide.util.lookup.InstanceContent ()); 102 } 103 104 private Lkp (org.openide.util.lookup.InstanceContent ic) { 105 super (ic); 106 this.ic = ic; 107 108 turn(c1); 109 } 110 111 public void turn (MIMEResolver c) { 112 ArrayList<Object > l = new ArrayList<Object >(); 113 l.add(err); 114 l.add(c); 115 ic.set (l, null); 116 } 117 } 118 119 120 private static class ErrMgr extends Handler { 121 public static boolean switchDone; 122 123 public ErrMgr() { 124 setLevel(Level.ALL); 125 } 126 127 public void publish(LogRecord r) { 128 String s = r.getMessage(); 129 130 if (s.startsWith ("Resolvers computed")) { 131 switchDone = true; 132 Lkp lkp = (Lkp)org.openide.util.Lookup.getDefault (); 133 lkp.turn (Lkp.c2); 134 } 135 } 136 137 public void flush() { 138 } 139 140 public void close() throws SecurityException { 141 } 142 143 } 144 145 } 146 | Popular Tags |