1 19 20 package org.openide.filesystems; 21 22 import org.netbeans.junit.NbTestCase; 23 import org.openide.util.Lookup; 24 import org.openide.util.lookup.AbstractLookup.Pair; 25 26 31 public class MIMESupport49418Test extends NbTestCase { 32 private FileSystem lfs; 33 private static FileObject mimeFo; 34 private static final String MIME_TYPE = "text/x-opqr"; 35 36 public MIMESupport49418Test(String name) { 37 super(name); 38 } 39 40 protected void setUp() throws Exception { 41 System.setProperty("org.openide.util.Lookup", "org.openide.filesystems.MIMESupport49418Test$Lkp"); 42 super.setUp(); 43 assertEquals("Our lookup is registered", Lkp.class, Lookup.getDefault().getClass()); 44 lfs = TestUtilHid.createLocalFileSystem(getName(), new String []{"A.opqr", }); 45 mimeFo = lfs.findResource("A.opqr"); 46 assertNotNull(mimeFo); 47 } 48 49 50 public void testMIMEResolution() 51 throws Exception { 52 assertNull(Lookup.getDefault().lookup(Runnable .class)); 53 assertEquals(MIME_TYPE, mimeFo.getMIMEType()); 54 55 } 56 57 60 @SuppressWarnings ("unchecked") 61 private static class QueryingPair extends Pair { 62 public boolean beBroken; 63 64 public String getId() { 65 return getType().toString(); 66 } 67 68 public String getDisplayName() { 69 return getId(); 70 } 71 72 public Class getType() { 73 return getClass(); 74 } 75 76 protected boolean creatorOf(Object obj) { 77 return obj == this; 78 } 79 80 protected boolean instanceOf(Class c) { 81 if (beBroken) { 82 beBroken = false; 83 assertEquals("content/unknown", mimeFo.getMIMEType()); 84 85 } 86 return c.isAssignableFrom(getType()); 87 } 88 89 public Object getInstance() { 90 return this; 91 } 92 } 93 94 95 public static final class Lkp extends org.openide.util.lookup.AbstractLookup { 96 private static org.openide.util.lookup.InstanceContent ic; 97 98 public Lkp() { 99 this(new org.openide.util.lookup.InstanceContent()); 100 } 101 102 private Lkp(org.openide.util.lookup.InstanceContent ic) { 103 super(ic); 104 this.ic = ic; 105 } 106 107 protected void initialize() { 108 for (int i = 0; i < 1000; i++) { 112 ic.add(new Integer (i)); 113 } 114 115 QueryingPair qp = new QueryingPair(); 116 ic.addPair(qp); 117 ic.add(new MIMEResolver() { 118 public String findMIMEType(FileObject fo) { 119 return MIME_TYPE; 120 } 121 }); 122 123 124 qp.beBroken = true; 125 } 126 127 } } 129 | Popular Tags |