KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > editor > mimelookup > MimePathMemoryTest


1 /*
2  * DummyMemoryTest.java
3  *
4  * Created on June 13, 2006, 9:33 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.api.editor.mimelookup;
11
12 import org.netbeans.junit.NbTestCase;
13 import org.netbeans.modules.editor.mimelookup.TestUtilities;
14
15 /**
16  *
17  * @author vita
18  */

19 public class MimePathMemoryTest extends NbTestCase {
20     
21     /** Creates a new instance of DummyMemoryTest */
22     public MimePathMemoryTest(String JavaDoc name) {
23         super(name);
24     }
25
26     public void testSimple() {
27         MimePath pathA = MimePath.get("text/x-java");
28         MimePath pathB = MimePath.get("text/x-java");
29         assertSame("MimePath instances are not cached and reused", pathA, pathB);
30     }
31     
32     public void testListOfRecentlyUsed() {
33         int idA = System.identityHashCode(MimePath.get("text/x-java"));
34
35         TestUtilities.consumeAllMemory();
36         TestUtilities.gc();
37         
38         int idB = System.identityHashCode(MimePath.get("text/x-java"));
39         
40         // The same instance of MimePath should still be in the cache
41
assertEquals("The MimePath instance was lost", idA, idB);
42         
43         for (int i = 0; i < MimePath.MAX_LRU_SIZE; i++) {
44             MimePath.get("text/x-nonsense-" + i);
45         }
46         
47         // Now the original text/x-java MimePath should be discarded
48
TestUtilities.consumeAllMemory();
49         TestUtilities.gc();
50         
51         int idC = System.identityHashCode(MimePath.get("text/x-java"));
52         assertTrue("The MimePath instance was not release", idA != idC);
53     }
54 }
55
Popular Tags