KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > filebasedfs > fileobjects > MutualExclusionSupportTest


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
20 package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.junit.NbTestCase;
24
25 /**
26  * ResourcePoolTest.java
27  * JUnit based test
28  *
29  * @author Radek Matous
30  */

31 public class MutualExclusionSupportTest extends NbTestCase {
32
33     public MutualExclusionSupportTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     /**
38      * Test of addResource method, of class org.netbeans.modules.masterfs.filebasedfs.streams.ResourcePool.
39      */

40     public void testAddResource() throws Exception JavaDoc {
41         Object JavaDoc key = new String JavaDoc ("key");
42         
43         MutualExclusionSupport.Closeable rem1 = MutualExclusionSupport.getDefault().addResource(key, true);
44         MutualExclusionSupport.Closeable rem2 = MutualExclusionSupport.getDefault().addResource(key, true);
45         
46         try {
47             MutualExclusionSupport.Closeable rem3 = MutualExclusionSupport.getDefault().addResource(key, false);
48             fail ();
49         } catch (IOException JavaDoc iox) {}
50         
51         rem1.close();
52         
53         try {
54             MutualExclusionSupport.Closeable rem3 = MutualExclusionSupport.getDefault().addResource(key, false);
55             fail ();
56         } catch (IOException JavaDoc iox) {}
57         
58         rem2.close();
59         
60         try {
61             MutualExclusionSupport.Closeable rem3 = MutualExclusionSupport.getDefault().addResource(key, false);
62             rem3.close();
63         } catch (IOException JavaDoc iox) {
64             fail ();
65         }
66         
67         MutualExclusionSupport.Closeable rem4 = MutualExclusionSupport.getDefault().addResource(key, false);
68
69         try {
70             rem1 = MutualExclusionSupport.getDefault().addResource(key, true);
71             fail ();
72         } catch (IOException JavaDoc iox) {
73         }
74         
75         try {
76             MutualExclusionSupport.Closeable rem3 = MutualExclusionSupport.getDefault().addResource(key, false);
77             fail ();
78         } catch (IOException JavaDoc iox) {
79         }
80         
81         rem4.close();
82         rem1 = MutualExclusionSupport.getDefault().addResource(key, true);
83         rem1.close();
84         MutualExclusionSupport.Closeable rem3 = MutualExclusionSupport.getDefault().addResource(key, false);
85         rem3.close();
86     }
87     
88     // TODO add test methods here. The name must begin with 'test'. For example:
89
// public void testHello() {}
90

91 }
92
Popular Tags