KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > registry > mergedctx > ReusedBindingTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc name) {
36         super(name);
37     }
38
39     protected void setUp() throws Exception JavaDoc {
40         super.setUp();
41         getRootContext();
42     }
43
44     protected FileObject getRoot() {
45         return SetUpUtils.getSimpleRoot();
46     }
47
48     protected FileObject findResource(String JavaDoc 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 JavaDoc bindingName = "myBindingName";
57         final String JavaDoc value = "myValue";
58         final String JavaDoc defValue = "defValue";
59         Object JavaDoc obj;
60
61         ctx.putString(bindingName, value);
62         //assertEquals("Unexpected: different instances",value, ctx.getString(bindingName,""));
63

64         ctx.putString(bindingName, null);
65 /*
66         obj = ctx.getObject(bindingName,defValue);
67         assertTrue("Unexpected different instances: "+obj,obj == defValue);
68 */

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