1 19 20 package org.netbeans.core; 21 22 import java.io.*; 23 import java.util.*; 24 import org.openide.filesystems.*; 25 import org.openide.actions.*; 26 import org.openide.util.actions.SystemAction; 27 28 29 33 public class LoaderPoolNodeTest extends org.netbeans.junit.NbTestCase { 34 private OldStyleLoader oldL; 35 private NewStyleLoader newL; 36 37 public LoaderPoolNodeTest (String testName) { 38 super (testName); 39 } 40 41 protected void setUp () throws java.lang.Exception { 42 LoaderPoolNode.installationFinished(); 43 44 oldL = (OldStyleLoader)OldStyleLoader.getLoader (OldStyleLoader.class); 45 newL = (NewStyleLoader)NewStyleLoader.getLoader (NewStyleLoader.class); 46 LoaderPoolNode.doAdd (oldL, null); 47 LoaderPoolNode.doAdd (newL, null); 48 LoaderPoolNode.waitFinished(); 49 } 50 51 protected void tearDown () throws java.lang.Exception { 52 LoaderPoolNode.remove (oldL); 53 LoaderPoolNode.remove (newL); 54 } 55 56 public void testOldLoaderThatChangesActionsBecomesModified () throws Exception { 57 assertFalse ("Not modified at begining", LoaderPoolNode.isModified (oldL)); 58 Object actions = oldL.getActions (); 59 assertNotNull ("Some actions there", actions); 60 assertTrue ("Default actions called", oldL.defaultActionsCalled); 61 assertFalse ("Still not modified", LoaderPoolNode.isModified (oldL)); 62 63 ArrayList list = new ArrayList (); 64 list.add (OpenAction.get (OpenAction.class)); 65 list.add (NewAction.get (NewAction.class)); 66 oldL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); 67 68 assertTrue ("Now it is modified", LoaderPoolNode.isModified (oldL)); 69 List l = Arrays.asList (oldL.getActions ()); 70 assertEquals ("Actions are the same", list, l); 71 } 72 73 public void testNewLoaderThatChangesActionsBecomesModified () throws Exception { 74 assertFalse ("Not modified at begining", LoaderPoolNode.isModified (newL)); 75 Object actions = newL.getActions (); 76 assertNotNull ("Some actions there", actions); 77 assertTrue ("Default actions called", newL.defaultActionsCalled); 78 assertFalse ("Still not modified", LoaderPoolNode.isModified (newL)); 79 80 ArrayList list = new ArrayList (); 81 list.add (OpenAction.get (OpenAction.class)); 82 list.add (NewAction.get (NewAction.class)); 83 newL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); 84 85 assertFalse ("Even if we changed actions, it is not modified", LoaderPoolNode.isModified (newL)); 86 List l = Arrays.asList (newL.getActions ()); 87 assertEquals ("But actions are changed", list, l); 88 } 89 90 public static class OldStyleLoader extends org.openide.loaders.UniFileLoader { 91 boolean defaultActionsCalled; 92 93 public OldStyleLoader () { 94 super (org.openide.loaders.MultiDataObject.class); 95 } 96 97 protected org.openide.loaders.MultiDataObject createMultiObject (FileObject fo) throws IOException { 98 throw new IOException ("Not implemented"); 99 } 100 101 protected SystemAction[] defaultActions () { 102 defaultActionsCalled = true; 103 SystemAction[] retValue; 104 105 retValue = super.defaultActions(); 106 return retValue; 107 } 108 109 110 } 111 112 public static final class NewStyleLoader extends OldStyleLoader { 113 protected String actionsContext () { 114 return "Loaders/IamTheNewBeggining"; 115 } 116 } 117 } 118 | Popular Tags |