Index: lutinutil/src/test/org/codelutin/util/LRUMapMultiKeyTest.java diff -u /dev/null lutinutil/src/test/org/codelutin/util/LRUMapMultiKeyTest.java:1.1 --- /dev/null Tue May 23 13:56:17 2006 +++ lutinutil/src/test/org/codelutin/util/LRUMapMultiKeyTest.java Tue May 23 13:56:12 2006 @@ -0,0 +1,117 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * LRUMapMultiKeyTest.java + * + * Created: 23 mai 2006 04:57:50 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/05/23 13:56:12 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.util.List; + +import junit.framework.TestCase; + + +/** + * @author poussin + * + */ + +public class LRUMapMultiKeyTest extends TestCase { + + + /* + * Test method for 'org.codelutin.util.LRUMapMultiKey.clear()' + */ + public void testClear() { +System.out.println("testClear"); + LRUMapMultiKey map = new LRUMapMultiKey(10); + LRUMapMultiKey.Key key1 = map.createKey("testClear", "toto", "tyty", "tutu"); + LRUMapMultiKey.Key key2 = map.createKey("toto", "titi", "tutu"); + LRUMapMultiKey.Key key3 = map.createKey("toto", "titi", "tata"); + + map.put(key1, "value"); + map.put(key2, "value"); + map.put(key3, "value"); + + map.clear(); + + assertEquals(0, map.size()); + assertEquals(0, map.keys.size()); + } + + /* + * Test method for 'java.util.WeakHashMap.get(Object)' + */ + public void testGet() throws Exception { +System.out.println("testGet"); + LRUMapMultiKey map = new LRUMapMultiKey(1); + + LRUMapMultiKey.Key key1 = map.createKey("toto", "titi", "tutu"); + map.put(key1, "value1"); + + assertEquals("value1", map.get(map.createKey("toto", "titi", "tutu"))); + + + LRUMapMultiKey.Key key2 = map.createKey("tyty"); + map.put(key2, "value2"); + + assertEquals(null, map.get(key1)); + assertEquals("value2", map.get(key2)); + + assertEquals(1, map.size()); + assertEquals(1, map.keys.size()); + } + + /* + * Test method for 'java.util.WeakHashMap.remove(Object)' + */ + public void testRemoveObject() { +System.out.println("testRemoveObject"); + LRUMapMultiKey map = new LRUMapMultiKey(10); + LRUMapMultiKey.Key key1 = map.createKey("testRemoveObject", "toto", "tyty", "tutu"); + LRUMapMultiKey.Key key2 = map.createKey("toto", "titi", "tutu"); + LRUMapMultiKey.Key key3 = map.createKey("toto", "titi", "tata"); + + map.put(key1, "value"); + map.put(key2, "value"); + map.put(key3, "value"); + + Object l = map.remove("titi"); + + assertTrue(l instanceof List); + assertEquals(2, ((List)l).size()); + assertEquals(1, map.size()); + + map.remove(key1); + + assertEquals(0, map.size()); + } + +} + + Index: lutinutil/src/test/org/codelutin/util/TransparenteReferenceTest.java diff -u /dev/null lutinutil/src/test/org/codelutin/util/TransparenteReferenceTest.java:1.1 --- /dev/null Tue May 23 13:56:17 2006 +++ lutinutil/src/test/org/codelutin/util/TransparenteReferenceTest.java Tue May 23 13:56:12 2006 @@ -0,0 +1,71 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * TransparenteReferenceTest.java + * + * Created: 22 mai 2006 15:41:49 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/05/23 13:56:12 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + + +/** + * @author poussin + * + */ + +public class TransparenteReferenceTest extends TestCase { + + public void testHash() { + Map map = new HashMap(); + + String key = "key"; + TransparenteSoftReference keyRef = new TransparenteSoftReference(key); + + String value = "value"; + TransparenteSoftReference valueRef = new TransparenteSoftReference(value); + + map.put(keyRef, valueRef); + + + assertEquals(valueRef, map.get(keyRef)); + assertEquals(valueRef.get(), map.get(keyRef).get()); + key = null; + value = null; + + System.gc(); + Thread.yield(); + + assertEquals("value".hashCode(), map.get(keyRef).hashCode()); + } +} + +