1 19 20 package org.openide.filesystems; 21 22 import junit.framework.*; 23 import org.netbeans.junit.*; 24 25 import java.io.*; 26 import java.util.*; 27 28 import org.openide.filesystems.*; 29 30 31 36 public abstract class FileSystemFactoryHid extends NbTestSetup { 37 private static Map<Test, List<FileSystemFactoryHid>> map = 38 new HashMap<Test, List<FileSystemFactoryHid>> (); 39 private static String className; 40 41 42 44 public FileSystemFactoryHid(Test test) { 45 super(test); 46 47 registerMap (test); 48 } 49 50 56 final static FileSystem[] createFileSystem (String testName,String [] resources, Test test) throws IOException { 57 return getInstance (test,true).createFileSystem(testName, resources); 58 } 59 60 final static void destroyFileSystem (String testName, Test test) throws IOException { 61 getInstance (test,false).destroyFileSystem(testName); 62 } 63 64 final static String getResourcePrefix (String testName, Test test, String [] resources) { 65 return getInstance (test,false).getResourcePrefix(testName, resources); 66 } 67 68 69 70 private final static FileSystemFactoryHid getInstance (Test test, boolean delete) { 71 FileSystemFactoryHid factory = getFromMap (test,delete); 72 if (factory != null) 73 className = factory.getClass().getName(); 74 return factory; 75 } 76 77 final static String getTestClassName () { 78 return (className != null) ? className : "Unknown TestSetup"; 79 } 80 81 84 protected abstract FileSystem[] createFileSystem(String testName, String [] resources) throws IOException; 85 86 protected abstract void destroyFileSystem(String testName) throws IOException; 87 88 protected String getResourcePrefix (String testName, String [] resources) { 89 return ""; 90 } 91 92 93 private void registerMap (Test test) { 94 if (test instanceof TestSuite) { 95 Enumeration en = ((TestSuite)test).tests (); 96 while (en.hasMoreElements()) { 97 Test tst = (Test)en.nextElement(); 98 if (tst instanceof TestSuite) 99 registerMap (tst); 100 else { 101 addToMap (tst); 102 } 103 } 104 } else { 105 addToMap (test); 106 } 107 } 108 109 private void addToMap (Test test) { 110 List<FileSystemFactoryHid> s = map.get (test); 111 if (s == null) { 112 s = new LinkedList<FileSystemFactoryHid>(); 113 } 114 s.add(this); 115 map.put(test ,s ); 116 117 } 118 119 120 private static FileSystemFactoryHid getFromMap (Test test, boolean delete) { 121 LinkedList s = (LinkedList)map.get (test); 122 FileSystemFactoryHid retVal; 123 try { 124 retVal = (FileSystemFactoryHid)s.getLast(); 125 } catch (NoSuchElementException x ) { 126 System.out.println("exc: "+ test + " : " ); 127 throw x; 128 } 129 if (delete) { 130 s.remove(retVal); 131 } 132 return retVal; 133 } 134 } 135 | Popular Tags |