1 7 package test.beans; 8 9 import java.beans.PropertyEditor ; 10 import java.beans.PropertyEditorManager ; 11 import java.beans.PropertyEditorSupport ; 12 import java.io.ObjectInput ; 13 import java.io.ObjectInputStream ; 14 import java.io.ObjectOutput ; 15 import java.io.ObjectOutputStream ; 16 import java.util.Arrays ; 17 import java.util.List ; 18 19 import junit.framework.TestCase; 20 21 import org.ejtools.beans.CustomPropertyEditorManager; 22 23 27 public class CustomPropertyEditorManagerTest extends TestCase 28 { 29 30 public CustomPropertyEditorManagerTest() 31 { 32 super(); 33 } 34 35 36 41 public CustomPropertyEditorManagerTest(String name) 42 { 43 super(name); 44 } 45 46 47 48 public void testInitialization() 49 { 50 List paths = null; 51 52 String [] beforePaths = PropertyEditorManager.getEditorSearchPath(); 53 54 CustomPropertyEditorManager.findEditor(String .class); 56 String path = CustomPropertyEditorManager.EDITORS_PACKAGE; 57 58 String [] afterPaths = PropertyEditorManager.getEditorSearchPath(); 59 60 paths = Arrays.asList(beforePaths); 61 if (paths.contains(path)) 62 { 63 fail("Must not find " + path + " among the paths"); 64 } 65 66 paths = Arrays.asList(afterPaths); 67 if (!paths.contains(path)) 68 { 69 fail("Must find " + path + " among the paths"); 70 } 71 } 72 73 74 75 public void testSearch() 76 { 77 PropertyEditor pe = null; 78 79 pe = CustomPropertyEditorManager.findEditor(String .class); 80 assertNotNull("Must find at least one property editor", pe); 81 82 pe = CustomPropertyEditorManager.findEditor(Thread .class); 83 assertNull("Must not find a property editor", pe); 84 85 PropertyEditorManager.registerEditor(ObjectInput .class, InputStreamPropertyEditor.class); 86 PropertyEditorManager.registerEditor(ObjectOutput .class, OutputStreamPropertyEditor.class); 87 88 pe = CustomPropertyEditorManager.findEditor(ObjectInputStream .class); 89 assertNotNull("Must find one property editor", pe); 90 assertEquals("Must find one property editor", pe.getClass(), InputStreamPropertyEditor.class); 91 92 pe = CustomPropertyEditorManager.findEditor(ObjectOutputStream .class); 93 assertNotNull("Must find one property editor", pe); 94 assertEquals("Must find one property editor", pe.getClass(), OutputStreamPropertyEditor.class); 95 } 96 97 98 104 public static class InputStreamPropertyEditor extends PropertyEditorSupport 105 { 106 } 107 108 109 115 public static class OutputStreamPropertyEditor extends PropertyEditorSupport 116 { 117 } 118 } 119 | Popular Tags |