1 19 package org.openide.filesystems; 20 import java.io.IOException ; 21 import org.netbeans.junit.NbTestCase; 22 import org.openide.ErrorManager; 23 import org.openide.util.Lookup; 24 import org.openide.util.lookup.InstanceContent; 25 26 30 public class MIMESupport68318Test extends NbTestCase { 31 static { 32 System.setProperty("org.openide.util.Lookup", "org.openide.filesystems.MIMESupport68318Test$Lkp"); 33 } 34 35 public MIMESupport68318Test(String testName) { 36 super(testName); 37 } 38 39 protected void setUp() throws Exception { 40 ErrorManager.getDefault().log("Just initialize the ErrorManager"); 41 } 42 43 protected void tearDown() throws Exception { 44 } 45 46 public void testQueryMIMEFromInsideTheLookup() throws IOException { 47 Lkp l = (Lkp)Lookup.getDefault(); 48 { 49 MIMEResolver[] result = MIMESupport.getResolvers(); 50 assertEquals("One is there", 1, result.length); 51 assertEquals("It is c1", Lkp.c1, result[0]); 52 53 assertNotNull("Result computed", l.result); 54 assertEquals("But it has to be empty", 0, l.result.length); 55 } 56 57 l.result = null; 58 l.ic.add(Lkp.c2); 59 60 { 61 MIMEResolver[] result = MIMESupport.getResolvers(); 62 assertEquals("Now two", 2, result.length); 63 assertEquals("It is c1", Lkp.c1, result[0]); 64 assertEquals("and c2", Lkp.c2, result[1]); 65 66 assertNotNull("Result in lookup computed", l.result); 67 assertEquals("And it contains the previous result", 1, l.result.length); 68 assertEquals("which is c1", Lkp.c1, l.result[0]); 69 } 70 } 71 72 public static final class Lkp extends org.openide.util.lookup.AbstractLookup { 73 static MIMEResolver c1 = new MIMEResolver() { 74 public String findMIMEType(FileObject fo) { 75 return null; 76 } 77 78 public String toString() { 79 return "C1"; 80 } 81 }; 82 static MIMEResolver c2 = new MIMEResolver() { 83 public String findMIMEType(FileObject fo) { 84 return null; 85 } 86 87 public String toString() { 88 return "C2"; 89 } 90 }; 91 private MIMEResolver[] result; 92 93 94 public InstanceContent ic; 95 public Lkp () { 96 this (new InstanceContent ()); 97 } 98 99 private Lkp (InstanceContent ic) { 100 super (ic); 101 this.ic = ic; 102 103 ic.add(c1); 104 } 105 106 protected void beforeLookup(org.openide.util.Lookup.Template template) { 107 if (template.getType() == MIMEResolver.class) { 108 assertNull("First invocation to assign result", result); 109 result = MIMESupport.getResolvers(); 110 } 111 } 112 113 114 } 115 116 } 117 | Popular Tags |