1 19 package org.netbeans.api.registry.mergedctx; 20 21 import org.netbeans.api.registry.BindingTest; 22 import org.netbeans.api.registry.Context; 23 import org.netbeans.api.registry.ContextException; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.Repository; 26 27 public class ReusedBindingTest extends BindingTest { 28 private Context rootCtx; 29 protected Context getRootContext() { 30 if (rootCtx == null) 31 rootCtx = SetUpUtils.getSimpleContext(super.getRootContext()); 32 return rootCtx; 33 } 34 35 public ReusedBindingTest(String name) { 36 super(name); 37 } 38 39 protected void setUp() throws Exception { 40 super.setUp(); 41 getRootContext(); 42 } 43 44 protected FileObject getRoot() { 45 return SetUpUtils.getSimpleRoot(); 46 } 47 48 protected FileObject findResource(String resource) { 49 if (resource.startsWith("/")) 50 resource = resource.substring(1); 51 return Repository.getDefault ().findResource ("first/"+resource); 52 } 53 54 public void testFlipFlap () throws ContextException{ 55 Context ctx = getRootContext().createSubcontext("test");; 56 String bindingName = "myBindingName"; 57 final String value = "myValue"; 58 final String defValue = "defValue"; 59 Object obj; 60 61 ctx.putString(bindingName, value); 62 64 ctx.putString(bindingName, null); 65 69 70 ctx.putString(bindingName, value); 71 obj = ctx.getString(bindingName,""); 72 assertEquals("Unexpected: different instances: " + obj,value, obj); 73 74 ctx.putString(bindingName, null); 75 obj = ctx.getObject(bindingName,defValue); 76 assertTrue("Unexpected different instances: "+obj,obj == defValue); 77 78 } 79 80 } 81 | Popular Tags |