[Arakhnę-Dev] [28] Add unit tests.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 28
Author:   galland
Date:     2009-02-02 21:43:13 +0100 (Mon, 02 Feb 2009)

Log Message:
-----------
Add unit tests.

Added Paths:
-----------
    trunk/arakhneRefs/src/test/java/org/arakhne/
    trunk/arakhneRefs/src/test/java/org/arakhne/junit/
    trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractRepeatedTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractTestCase.java
    trunk/arakhneRefs/src/test/java/org/arakhne/junit/RepeatableTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueMapTest.java


Added: trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractRepeatedTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractRepeatedTest.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractRepeatedTest.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,150 @@
+/* $Id$
+ * 
+ * Copyright (C) 2007 Stéphane GALLAND
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.junit;
+
+import java.lang.ref.WeakReference;
+import java.util.Enumeration;
+
+import junit.extensions.TestDecorator;
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestListener;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+/** Test case that repeat another test.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ */
+public abstract class AbstractRepeatedTest extends TestDecorator {
+	
+	private final int fTimesRepeat;
+
+	public AbstractRepeatedTest(Class<? extends RepeatableTest> clazz, int repeat) {
+		this(new RepeatableTestSuite(clazz),repeat);
+	}
+
+	public AbstractRepeatedTest(Test test, int repeat) {
+		super(test);
+		if (repeat < 0)
+			throw new IllegalArgumentException("Repetition count must be > 0"); //$NON-NLS-1$
+		this.fTimesRepeat= repeat;
+	}
+	
+	@Override
+	public int countTestCases() {
+		return super.countTestCases()*this.fTimesRepeat;
+	}
+	
+	@Override
+	public void run(TestResult result) {
+		
+		final TestResultHandler handler = new TestResultHandler(result);
+		result.addListener(handler);
+
+		try {
+			for (int i= 0; i < this.fTimesRepeat; i++) {
+				if (result.shouldStop())
+					break;
+				((RepeatableTest)this.fTest).setLoopIndex(i);
+				try {
+					super.run(result);
+				}
+				finally {
+					((RepeatableTest)this.fTest).setLoopIndex(-1);
+				}
+			}
+		}
+		finally {
+			result.removeListener(handler);
+		}
+	}
+	
+	@Override
+	public String toString() {
+		int idx = ((RepeatableTest)this.fTest).getLoopIndex();
+		if (idx>0)
+			return super.toString()+"(repeated "+idx+"/"+this.fTimesRepeat+")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		return super.toString()+"(repeated)"; //$NON-NLS-1$
+	}
+	
+	/** Handler on test result errors for a repeated test.
+	 *
+	 * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+	 * @version $Name$ $Revision$ $Date$
+	 */
+	private class TestResultHandler implements TestListener {
+
+		private WeakReference<TestResult> result;
+		
+		public TestResultHandler(TestResult result) {
+			this.result = new WeakReference<TestResult>(result);
+		}
+		
+		public void addError(Test test, Throwable t) {
+			TestResult r = this.result.get();
+			if (r!=null) r.stop();
+		}
+
+		public void addFailure(Test test, AssertionFailedError t) {
+			TestResult r = this.result.get();
+			if (r!=null) r.stop();
+		}
+
+		public void endTest(Test test) {
+			//
+		}
+
+		public void startTest(Test test) {
+			//
+		}
+		
+	} /* class TestResultHandler */
+	
+	/** Test suite that could be repeated.
+	 *
+	 * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+	 * @version $Name$ $Revision$ $Date$
+	 */
+	private static class RepeatableTestSuite extends TestSuite implements RepeatableTest {
+		
+		private int loopIndex = -1;
+		
+		public RepeatableTestSuite(Class<? extends RepeatableTest> clazz) {
+			super(clazz);
+		}
+
+		public void setLoopIndex(int index) {
+			this.loopIndex = index;
+			Enumeration<?> e = tests();
+			while (e.hasMoreElements()) {
+				RepeatableTest t = (RepeatableTest)e.nextElement();
+				t.setLoopIndex(index);
+			}
+		}
+		
+		public int getLoopIndex() {
+			return this.loopIndex;
+		}
+		
+	}
+
+}

Added: trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractTestCase.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractTestCase.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/junit/AbstractTestCase.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,566 @@
+package org.arakhne.junit;
+
+import java.awt.geom.Point2D;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Map.Entry;
+
+import org.arakhne.junit.RepeatableTest;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+public abstract class AbstractTestCase extends TestCase implements RepeatableTest {
+	
+	private static String arrayToString(Object o) {
+		if (o==null) return null;
+		if (o instanceof boolean[])
+			return Arrays.toString((boolean[])o);
+		if (o instanceof byte[])
+			return Arrays.toString((byte[])o);
+		if (o instanceof char[])
+			return Arrays.toString((char[])o);
+		if (o instanceof short[])
+			return Arrays.toString((short[])o);
+		if (o instanceof int[])
+			return Arrays.toString((int[])o);
+		if (o instanceof long[])
+			return Arrays.toString((long[])o);
+		if (o instanceof float[])
+			return Arrays.toString((float[])o);
+		if (o instanceof double[])
+			return Arrays.toString((double[])o);
+		if (o instanceof Object[])
+			return Arrays.toString((Object[])o);
+		return o.toString();
+	}
+
+	/** Replies if the given elements is in the array.
+	 * <p>
+	 * This function is based on {@link Object#equals(java.lang.Object)}.
+	 */
+	private static <T> boolean arrayContainsAll(T[] elts, T[] array) {
+		boolean found;
+		for (T elt : elts) {
+			found = false;
+			for (T t : array) {
+				if ((t==elt)||
+					((t!=null)&&(t.equals(elt)))) {
+					found = true;
+					break;
+				}
+			}
+			if (!found) return false;
+		}
+		return true;
+	}
+
+	private int loopIndex = -1;
+
+	public int getLoopIndex() {
+		return this.loopIndex;
+	}
+
+	public void setLoopIndex(int index) {
+		this.loopIndex = index;
+	}
+
+	protected  String formatFailMessage(String message, Object expected, Object actual) {
+		StringBuffer formatted = new StringBuffer();
+		if (message!=null) {
+			formatted.append(message);
+			formatted.append(' ');
+		}
+		formatted.append("expected:<"); //$NON-NLS-1$
+		formatted.append(arrayToString(expected));
+		formatted.append("> but was:<"); //$NON-NLS-1$
+		formatted.append(arrayToString(actual));
+		formatted.append(">"); //$NON-NLS-1$
+		return formatted.toString();
+	}
+
+	protected  String formatFailMessage(String message, String msg, Object actual) {
+		StringBuffer formatted = new StringBuffer();
+		if (message!=null) {
+			formatted.append(message);
+			formatted.append(' ');
+		}
+		formatted.append(msg);
+		formatted.append(" but was:<"); //$NON-NLS-1$
+		formatted.append(arrayToString(actual));
+		formatted.append(">"); //$NON-NLS-1$
+		return formatted.toString();
+	}
+
+	protected String formatFailNegMessage(String message, Object notexpected) {
+		StringBuffer formatted = new StringBuffer();
+		if (message!=null) {
+			formatted.append(message);
+			formatted.append(' ');
+		}
+		formatted.append("not expected:<"); //$NON-NLS-1$
+		formatted.append(arrayToString(notexpected));
+		formatted.append("> but the same"); //$NON-NLS-1$
+		return formatted.toString();
+	}
+
+	/** Asserts that two objects are not equal. If they are
+	 * an AssertionFailedError is thrown with the given message.
+	 */
+	protected void assertNotEquals(String message, Object notexpected, Object actual) {
+		if ((notexpected!=actual)&&
+			((notexpected==null)
+			 ||
+			 (!notexpected.equals(actual)))) return;
+		fail(formatFailNegMessage(message, notexpected));
+	}
+
+	/** Asserts that two objects are not equal. If they are
+	 * an AssertionFailedError is thrown with the given message.
+	 */
+	protected void assertNotEquals(Object notexpected, Object actual) {
+	    assertNotEquals(null, notexpected, actual);
+	}
+	
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown with the given message.
+	 */
+	protected void assertEquals(String message, Object[] expectedObjects, Object actual) {
+		if ((expectedObjects!=null)&&(expectedObjects.length>0)) {
+			for (Object object : expectedObjects) {
+				if ((object==null)&&(actual==null)) return;
+				if ((object!=null)&&(object.equals(actual))) return;
+			}
+		}
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected void assertEquals(Object[] expectedObjects, Object actual) {
+	    assertEquals(null, expectedObjects, actual);
+	}
+
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown with the given message.
+	 */
+	protected <T> void assertEquals(String message, T[] expectedObjects, T[] actual) {
+		if (expectedObjects==actual) return;
+		if ((expectedObjects!=null)&&(actual!=null)&&
+			(expectedObjects.length==actual.length)) {
+			boolean ok = true;
+			for(int i=0; i<expectedObjects.length; i++) {
+				if ((expectedObjects[i]!=null)||(actual[i]!=null)) {
+					if ((expectedObjects[i]==null)||(!expectedObjects[i].equals(actual[i]))) {
+						ok = false;
+						break;
+					}
+				}
+			}
+			if (ok) return;
+		}
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertEquals(T[] expectedObjects, T[] actual) {
+	    assertEquals(null, expectedObjects, actual);
+	}
+
+	/** Asserts that the actuel object is not equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown with the given message.
+	 */
+	protected <T> void assertNotEquals(String message, T[] expectedObjects, T[] actual) {
+		if (expectedObjects!=actual) {			
+			if ((expectedObjects!=null)&&(actual!=null)) {
+				if (expectedObjects.length!=actual.length) return;
+				boolean ok = true;
+				for(int i=0; i<expectedObjects.length; i++) {
+					if ((expectedObjects[i]!=null)||(actual[i]!=null)) {
+						if ((expectedObjects[i]==null)||(!expectedObjects[i].equals(actual[i]))) {
+							ok = false;
+							break;
+						}
+					}
+				}
+				if (!ok) return;
+			}
+			else return;
+		}
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actuel object is not equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertNotEquals(T[] expectedObjects, T[] actual) {
+	    assertNotEquals(null, expectedObjects, actual);
+	}
+
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 * This assertion function tests the types of its parameters to call the best
+	 * {@code assertEquals} function.
+	 * 
+	 * @see #assertEquals(Object, Object)
+	 * @see #assertEquals(Object[], Object)
+	 * @see #assertEquals(Object[], Object[])
+	 */
+	protected void assertEqualsGeneric(Object expected, Object actual) {
+		assertEqualsGeneric(null, expected, actual);
+	}
+
+	/** Asserts that the actuel object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 * This assertion function tests the types of its parameters to call the best
+	 * {@code assertEquals} function.
+	 * 
+	 * @see #assertEquals(Object, Object)
+	 * @see #assertEquals(Object[], Object)
+	 * @see #assertEquals(Object[], Object[])
+	 */
+	protected void assertEqualsGeneric(String message, Object expected, Object actual) {
+		if ((expected!=null)&&(actual!=null)&&(expected.getClass().isArray())) {
+			if (actual.getClass().isArray())
+				assertEquals(message, (Object[])expected, (Object[])actual);
+			else
+				assertEquals(message, (Object[])expected, actual);
+		}
+		else assertEquals(message, expected, actual);
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertSimilars(T[] expectedObjects, T[] actual) {
+	    assertSimilars(null, expectedObjects, actual);
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertSimilars(String message, T[] expectedObjects, T[] actual) {
+		if (expectedObjects==actual) return;
+		if ((arrayContainsAll(expectedObjects, actual))&&(arrayContainsAll(actual, expectedObjects)))
+			return;
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertSimilars(Collection<T> expectedObjects, Collection<T> actual) {
+	    assertSimilars(null, expectedObjects, actual);
+	}
+	
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertSimilars(String message, Collection<T> expectedObjects, Collection<T> actual) {
+		if (expectedObjects==actual) return;
+		if (similars(expectedObjects,actual)) return;
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+	
+	private <T> boolean similars(Collection<T> c1, Collection<T> c2) {
+		ArrayList<T> a = new ArrayList<T>();
+		a.addAll(c2);
+		for(T elt : c1) {
+			if (!a.remove(elt)) {
+				return false;
+			}
+		}
+		return a.isEmpty();
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertEquals(List<T> expectedObjects, List<T> actual) {
+	    assertEquals(null, expectedObjects, actual);
+	}
+	
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertEquals(String message, List<T> expectedObjects, List<T> actual) {
+		if (expectedObjects==actual) return;
+		if (equals(expectedObjects,actual)) return;
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	private <T> boolean equals(List<T> c1, List<T> c2) {
+		if (c1.size()!=c2.size()) return false;
+		int count = c1.size();
+		T e1, e2;
+		for(int i=0; i<count; i++) {
+			e1 = c1.get(i);
+			e2 = c2.get(i);
+			if ((e1!=e2)&&(!e1.equals(e2))) {
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	/** Asserts that the actuel similar is not equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertNotEquals(List<T> expectedObjects, List<T> actual) {
+	    assertNotEquals(null, expectedObjects, actual);
+	}
+	
+	/** Asserts that the actuel object is not equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T> void assertNotEquals(String message, List<T> expectedObjects, List<T> actual) {
+		if ((expectedObjects!=actual)&&(!equals(expectedObjects,actual))) return;
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actual object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	@SuppressWarnings("unchecked")
+	protected <T, X> void assertSimilars(String message, T expected, T actual) {
+		if (expected==actual) return;
+		if (expected instanceof Collection)
+			assertSimilars(message, (Collection)expected, (Collection)actual);
+		else if (expected instanceof Point2D)
+			assertSimilars(message, (Point2D)expected, (Point2D)actual);
+		else if (expected instanceof Date)
+			assertSimilars(message, (Date)expected, (Date)actual);
+		else if (expected.getClass().isArray())
+			assertSimilars(message, (X[])expected, (X[])actual);
+		else
+			assertEquals(message, expected, actual);
+	}
+
+	/** Asserts that the actual object is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <T, X> void assertNotSimilars(String message, T expected, T actual) {
+		if (expected!=actual) {
+			try {
+				assertSimilars(message,expected, actual);
+			}
+			catch(AssertionError _) {
+				// ok
+				return;
+			}
+			catch(AssertionFailedError _) {
+				// ok
+				return;
+			}
+		}		
+		fail(formatFailMessage(message, expected, actual));
+	}
+
+	/** Replies if the two objects are similars.
+	 */
+	protected <T, X> boolean isSimilarObjects(T obj1, T obj2) {
+		if (obj1==obj2) return true;
+		try {
+			assertSimilars(null,obj1, obj2);
+			return true;
+		}
+		catch(AssertionError _) {
+			return false;
+		}
+		catch(AssertionFailedError _) {
+			return false;
+		}
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <K,V> void assertDeepSimilars(Map<K,V> expectedObjects, Map<K,V> actual) {
+	    assertDeepSimilars(null, expectedObjects, actual);
+	}
+	
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <K,V> void assertDeepSimilars(String message, Map<K,V> expectedObjects, Map<K,V> actual) {
+		if (expectedObjects==actual) return;
+		if (similars(expectedObjects.keySet(), actual.keySet())) {
+			for(Entry<K,V> entry : expectedObjects.entrySet()) {
+				V v1 = entry.getValue();
+				V v2 = actual.get(entry.getKey());
+				assertSimilars(message, v1, v2);
+			}
+			// all values are correct
+			return;
+		}
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <K,V> void assertNotDeepSimilars(Map<K,V> expectedObjects, Map<K,V> actual) {
+	    assertNotDeepSimilars(null, expectedObjects, actual);
+	}
+	
+	/** Asserts that the actuel similar is equal to one of the expected objects. If not
+	 * an AssertionFailedError is thrown.
+	 */
+	protected <K,V> void assertNotDeepSimilars(String message, Map<K,V> expectedObjects, Map<K,V> actual) {
+		if (expectedObjects!=actual) {
+			if (!similars(expectedObjects.keySet(), actual.keySet())) return;
+			
+			for(Entry<K,V> entry : expectedObjects.entrySet()) {
+				V v1 = entry.getValue();
+				V v2 = actual.get(entry.getKey());
+				if (!isSimilarObjects(v1, v2)) return;
+			}
+		}
+		fail(formatFailMessage(message, expectedObjects, actual));
+	}
+
+	/** Asserts that the specified value is stricly negative.
+	 */
+	protected void assertStrictlyNegative(Number number) {
+		assertStrictlyNegative(null,number);
+	}
+
+	/** Asserts that the specified value is stricly negative.
+	 */
+	protected void assertStrictlyNegative(String message, Number number) {
+		if (number.doubleValue()<0.) return;
+		fail(formatFailMessage(message, "expected negative value", number)); //$NON-NLS-1$
+	}
+
+	/** Asserts that the specified value is stricly positive.
+	 */
+	protected void assertStrictlyPositive(Number number) {
+		assertStrictlyPositive(null,number);
+	}
+
+	/** Asserts that the specified value is stricly positive.
+	 */
+	protected void assertStrictlyPositive(String message, Number number) {
+		if (number.doubleValue()>0.) return;
+		fail(formatFailMessage(message, "expected positive value", number)); //$NON-NLS-1$
+	}
+
+	/** Asserts that the specified value is negative.
+	 */
+	protected void assertNegative(Number number) {
+		assertNegative(null,number);
+	}
+
+	/** Asserts that the specified value is negative.
+	 */
+	protected void assertNegative(String message, Number number) {
+		if (number.doubleValue()<=0.) return;
+		fail(formatFailMessage(message, "expected negative value", number)); //$NON-NLS-1$
+	}
+
+	/** Asserts that the specified value is positive.
+	 */
+	protected void assertPositive(Number number) {
+		assertPositive(null,number);
+	}
+
+	/** Asserts that the specified value is positive.
+	 */
+	protected void assertPositive(String message, Number number) {
+		if (number.doubleValue()>=0.) return;
+		fail(formatFailMessage(message, "expected positive value", number)); //$NON-NLS-1$
+	}
+
+	@SuppressWarnings("unchecked")
+	protected <T> T[] extractRandomValues(T[] availableValues) {
+		Random rnd = new Random();
+		int count = rnd.nextInt(500);
+		ArrayList<T> tab = new ArrayList<T>(count);
+		for(int i=0; i<count; i++) {
+			tab.add(availableValues[rnd.nextInt(availableValues.length)]);
+		}
+		Class<?> clazz = availableValues.getClass().getComponentType();
+		T[] array = (T[])Array.newInstance(clazz, tab.size());
+		tab.toArray(array);
+		tab.clear();
+		return array;
+	}
+	
+	/** Replies a randomized string.
+	 */
+	protected String randomString() {
+		return randomString(-1);
+	}
+
+	/** Replies a randomized string.
+	 */
+	protected String randomString(int maxSize) {
+		Random rnd = new Random();
+		StringBuffer b = new StringBuffer();
+		int count = rnd.nextInt(maxSize<=0 ? 255 : maxSize-1)+1;
+		for(int i=0; i<count; i++) {
+			char c = (char)('A' + rnd.nextInt(26));
+			b.append(c);
+		}
+		return b.toString();
+	}
+
+	/** Assert the the specified method thrown an exception
+	 * 
+	 * @param self is the calling object
+	 * @param method is the name of the method to invoke
+	 * @param types is the parameter types of the method
+	 * @param parameters is the parameter values to pass at invocation.
+	 */
+	protected void assertException(Object self, String method, Class<?>[] types, Object[] parameters) {
+		assertException(null, self, method, types, parameters);
+	}
+
+	/** Assert the the specified method thrown an exception
+	 * 
+	 * @param self is the calling object
+	 * @param method is the name of the method to invoke
+	 * @param types is the parameter types of the method
+	 * @param parameters is the parameter values to pass at invocation.
+	 */
+	protected void assertException(String message, Object self, String method, Class<?>[] types, Object[] parameters) {
+		try {
+			Class<?> clazz = self.getClass();
+			Method methodFunc = clazz.getMethod(method, types);
+			methodFunc.invoke(self, parameters);
+			fail((message==null ? "" : message)+"An exception was attempted but never thrown."); //$NON-NLS-1$ //$NON-NLS-2$
+		}
+		catch(Exception _) {
+			// Expected behavior
+		}
+	}
+
+	/** Assert the the specified method thrown an exception
+	 * 
+	 * @param self is the calling object
+	 * @param method is the name of the method to invoke
+	 */
+	protected void assertException(Object self, String method) {
+		assertException(null, self, method, new Class<?>[0], new Object[0]);
+	}
+
+	/** Assert the the specified method thrown an exception
+	 * 
+	 * @param self is the calling object
+	 * @param method is the name of the method to invoke
+	 */
+	protected void assertException(String message, Object self, String method) {
+		assertException(message, self, method, new Class<?>[0], new Object[0]);
+	}
+
+}

Added: trunk/arakhneRefs/src/test/java/org/arakhne/junit/RepeatableTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/junit/RepeatableTest.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/junit/RepeatableTest.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,39 @@
+/* $Id$
+ * 
+ * Copyright (C) 2007 St&eacute;phane GALLAND
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.junit;
+
+import junit.framework.Test;
+
+/** Test case that could be repeated.
+ *
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ */
+public interface RepeatableTest extends Test {
+	
+	public void setLoopIndex(int index);
+	
+	public int getLoopIndex();
+	
+	public void setName(String name);
+	
+	public String getName();
+
+}

Added: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueMapTest.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueMapTest.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,343 @@
+package org.arakhne.util.ref;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Random;
+import java.util.Map.Entry;
+
+import org.arakhne.junit.AbstractTestCase;
+
+public class SoftValueMapTest extends AbstractTestCase {
+
+	private static final int REFERENCE_SIZE = 0; 
+	
+	private final HashMap<String,String> reference = new HashMap<String,String>();
+	
+	private static void collect() {
+		System.gc();System.gc();System.gc();
+	}
+	
+	private void spawnReference() {
+		this.reference.clear();
+		Random rnd = new Random();
+		int count = rnd.nextInt(REFERENCE_SIZE+1)+5;
+		String str;
+		for(int i=0; i<count; i++) {
+			str = randomString(10);
+			this.reference.put(
+					Integer.toString(i)+str,
+					str);
+		}
+		str = null;
+	}
+	
+	private String getReferenceObject(int index) {
+		Object[] tab = this.reference.keySet().toArray();
+		return (String)tab[index];
+	}
+	
+	private Map<String,String> removeElementsFromReference() {
+		HashMap<String,String> removed = new HashMap<String,String>();
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		String key, value;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			key = getReferenceObject(index);
+			value = this.reference.remove(key);
+			removed.put(key,value);
+		}
+		key = null;
+		value =  null;
+		return removed;
+	}
+	
+	@Override
+	public void setUp() {
+		spawnReference();
+	}
+	
+	@Override
+	public void tearDown() {
+		this.reference.clear();
+	}
+	
+	public void testSoftValueMapMap() {
+        SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        assertDeepSimilars(this.reference, test);
+    }
+
+    public void testSize() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>();
+        assertEquals(0, test.size());
+        
+        test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference.size(), test.size());
+
+        Map<String,String> removed = removeElementsFromReference();
+        assertNotNull(removed);
+        int count = removed.size();
+        removed = null;
+		
+		collect();
+		
+        assertTrue(((this.reference.size()-count)<=test.size())||(this.reference.size()>test.size()));		
+    }
+
+    public void testIsEmpty() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>();
+        assertTrue(test.isEmpty());
+        
+        test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertFalse(test.isEmpty());
+        
+        removeElementsFromReference();
+
+		collect();
+		
+        assertFalse(test.isEmpty());
+        
+        this.reference.clear();
+
+		collect();
+		
+        assertFalse(test.isEmpty());
+    }
+	
+    public void testContainsKey() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertDeepSimilars(this.reference, test);
+
+        // Test the content
+		{
+			String elt;
+			Iterator<String> iter = this.reference.keySet().iterator(); 
+			while (iter.hasNext()) {
+				elt = iter.next();
+				assertTrue(test.containsKey(elt));
+			}
+			elt = null;
+		}
+		assertDeepSimilars(this.reference, test);
+
+        Map<String,String> removedElements = removeElementsFromReference();
+        int originalSize = removedElements.size() + this.reference.size();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+		assertNotDeepSimilars(this.reference, test);
+		
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+		removedElements = null;
+
+		// Collects the objects
+		collect();
+		
+        // Test the content
+		assertNotEquals(this.reference.size(), test.size());
+		for(String elt : this.reference.keySet()) {
+			assertTrue(test.containsKey(elt));
+		}
+    }
+
+    public void testContainsValue() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertDeepSimilars(this.reference, test);
+
+        // Test the content
+		{
+			String elt;
+			Iterator<String> iter = this.reference.values().iterator(); 
+			while (iter.hasNext()) {
+				elt = iter.next();
+				assertTrue(test.containsValue(elt));
+			}
+			elt = null;
+		}
+		assertDeepSimilars(this.reference, test);
+
+        Map<String,String> removedElements = removeElementsFromReference();
+        int originalSize = removedElements.size() + this.reference.size();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+		assertNotDeepSimilars(this.reference, test);
+		
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+		removedElements = null;
+
+		// Collects the objects
+		collect();
+		
+        // Test the content
+		assertNotEquals(this.reference.size(), test.size());
+		for(String elt : this.reference.values()) {
+			assertTrue(test.containsValue(elt));
+		}
+    }
+
+    public void testEntryIterator() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertTrue(this.reference.containsKey(e.getKey()));
+        		assertEquals(this.reference.get(e.getKey()),this.reference.get(e.getKey()));
+        	}
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+    		assertNotDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertTrue(baseElements.containsKey(e.getKey()));
+        		assertEquals(baseElements.get(e.getKey()),baseElements.get(e.getKey()));
+        	}
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertEquals(this.reference.get(e.getKey()),this.reference.get(e.getKey()));
+        	}
+    	}
+    }
+
+    public void testKeyIterator() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String k;
+        	Iterator<String> iter = test.keySet().iterator();
+        	while (iter.hasNext()) {
+        		k = iter.next();
+        		assertTrue(this.reference.containsKey(k));
+        	}
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    		String k;
+        	Iterator<String> iter = test.keySet().iterator();
+        	while (iter.hasNext()) {
+        		k = iter.next();
+        		assertTrue(baseElements.containsKey(k));
+        	}
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    	}
+    }
+
+    public void testValueIterator() {
+    	SoftValueMap<String,String> test = new SoftValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String v;
+        	Iterator<String> iter = test.values().iterator();
+        	while (iter.hasNext()) {
+        		v = iter.next();
+        		assertTrue(this.reference.containsValue(v));
+        	}
+        	v = null;
+        	iter = null;
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    		String v;
+        	Iterator<String> iter = test.values().iterator();
+        	while (iter.hasNext()) {
+        		v = iter.next();
+        		assertTrue(baseElements.containsValue(v));
+        	}
+        	v = null;
+        	iter = null;
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    	}
+    }
+
+}

Added: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,918 @@
+package org.arakhne.util.ref;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.arakhne.junit.AbstractTestCase;
+
+public class WeakArrayListTest extends AbstractTestCase {
+
+	private static final int REFERENCE_SIZE = 0; 
+	
+	private final ArrayList<String> reference = new ArrayList<String>();
+	
+	private static void collect() {
+		System.gc();System.gc();System.gc();
+	}
+	
+	private void spawnReference() {
+		this.reference.clear();
+		Random rnd = new Random();
+		int count = rnd.nextInt(REFERENCE_SIZE+1)+5;
+		for(int i=0; i<count; i++) {
+			this.reference.add(Integer.toString(i)+randomString(10));
+		}
+		Collections.sort(this.reference);	}
+	
+	@Override
+	public void setUp() {
+		spawnReference();
+	}
+	
+	@Override
+	public void tearDown() {
+		this.reference.clear();
+	}
+	
+	public void testWeakArrayListCollection() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        assertEquals(this.reference, test);
+    }
+
+    public void testSize() {
+        WeakArrayList<String> test = new WeakArrayList<String>();
+        assertEquals(0, test.size());
+        
+        test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference.size(), test.size());
+        
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);
+		}
+		
+		collect();
+		
+        assertEquals(this.reference.size(), test.size());		
+    }
+
+    public void testIsEmpty() {
+        WeakArrayList<String> test = new WeakArrayList<String>();
+        assertTrue(test.isEmpty());
+        
+        test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertFalse(test.isEmpty());
+        
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);
+		}
+
+		collect();
+		
+        assertFalse(test.isEmpty());
+        
+        this.reference.clear();
+
+		collect();
+		
+        assertTrue(test.isEmpty());
+    }
+
+    public void testContains() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        // Test the content
+		for(String elt : this.reference) {
+			assertTrue(test.contains(elt));
+		}
+        assertEquals(this.reference, test);
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		int originalSize = this.reference.size();
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+        assertNotEquals(this.reference, test);
+		for(String elt : this.reference) {
+			assertTrue(test.contains(elt));
+		}
+
+        // Test the removed elements
+		for(String elt : removedElements) {
+			assertTrue(test.contains(elt));
+		}
+		
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(this.reference.size(), test.size());
+        assertEquals(this.reference, test);
+		for(String elt : this.reference) {
+			assertTrue(test.contains(elt));
+		}
+    }
+
+    public void testEquals() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        assertTrue(test.equals(this.reference));
+        assertTrue(this.reference.equals(test));
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		int originalSize = this.reference.size();
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+        assertNotEquals(this.reference, test);
+        assertFalse(test.equals(this.reference));
+        assertFalse(this.reference.equals(test));
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(this.reference.size(), test.size());
+        assertEquals(this.reference, test);
+        assertTrue(test.equals(this.reference));
+        assertTrue(this.reference.equals(test));
+    }
+
+    public void testIterator() {
+    	WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+    	assertEquals(this.reference, test);
+	
+        // Test the content
+    	String s;
+    	int idx=0;
+    	Iterator<String> iter = test.iterator();
+    	while (iter.hasNext()) {
+    		s = iter.next();
+    		assertEquals(this.reference.get(idx), s);
+    		idx++;
+    	}
+
+        // Remove elements
+		ArrayList<String> baseElements = new ArrayList<String>(this.reference);
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	idx=0;
+    	iter = test.iterator();
+    	while (iter.hasNext()) {
+    		s = iter.next();
+    		assertEquals(baseElements.get(idx), s);
+    		idx++;
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	idx=0;
+    	iter = test.iterator();
+    	while (iter.hasNext()) {
+    		s = iter.next();
+    		assertEquals(this.reference.get(idx), s);
+    		idx++;
+    	}
+    }
+
+	public void testContainsAll() {
+    	WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+    	assertEquals(this.reference, test);
+	
+        // Test the content
+    	assertTrue(this.reference.containsAll(test));
+    	assertTrue(test.containsAll(this.reference));
+
+        // Remove elements
+		ArrayList<String> baseElements = new ArrayList<String>(this.reference);
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	assertFalse(this.reference.containsAll(test));
+    	assertTrue(test.containsAll(this.reference));
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	assertTrue(this.reference.containsAll(test));
+    	assertTrue(test.containsAll(this.reference));
+	}
+    
+	public void testToArray() {
+    	WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+    	assertEquals(this.reference, test);
+	
+        // Test the content
+    	assertEquals(this.reference.toArray(),test.toArray());
+
+        // Remove elements
+		ArrayList<String> baseElements = new ArrayList<String>(this.reference);
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	assertNotEquals(this.reference.toArray(),test.toArray());
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	assertEquals(this.reference.toArray(),test.toArray());
+	}
+	public void testToArrayArray() {
+    	WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+    	assertEquals(this.reference, test);
+    	
+    	String[] tab1, tab2;
+	
+        // Test the content
+    	tab1 = new String[this.reference.size()];
+    	this.reference.toArray(tab1);
+    	tab2 = new String[test.size()];
+    	test.toArray(tab2);
+    	assertEquals(tab1,tab2);
+    	Arrays.fill(tab1, null);
+    	Arrays.fill(tab2, null);
+
+        // Remove elements
+		ArrayList<String> baseElements = new ArrayList<String>(this.reference);
+		Collections.sort(baseElements);
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			this.reference.remove(index);			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	tab1 = new String[this.reference.size()];
+    	this.reference.toArray(tab1);
+    	tab2 = new String[test.size()];
+    	test.toArray(tab2);
+    	assertNotEquals(tab1,tab2);
+    	Arrays.fill(tab1, null);
+    	Arrays.fill(tab2, null);
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	tab1 = new String[this.reference.size()];
+    	this.reference.toArray(tab1);
+    	tab2 = new String[test.size()];
+    	test.toArray(tab2);
+    	assertEquals(tab1,tab2);
+    	Arrays.fill(tab1, null);
+    	Arrays.fill(tab2, null);
+	}
+
+	public void testClear() {
+    	WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+    	
+        // Remove elements
+    	test.clear();
+
+		// Collects the objects
+		collect();
+
+    	assertTrue(test.isEmpty());
+	}
+
+	public void testIndexOf() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        // Test the content
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(index, test.indexOf(this.reference.get(index)));
+		}
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		count = rnd.nextInt(this.reference.size()/4)+1;
+		int minIndex = Integer.MAX_VALUE;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex) minIndex = index;
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex)
+				assertEquals(index, test.indexOf(this.reference.get(index)));
+			else
+				assertFalse(index==test.indexOf(this.reference.get(index)));
+		}
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size());
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(index, test.indexOf(this.reference.get(index)));
+		}
+	}
+	
+	public void testLastIndexOf() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        // Test the content
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(index, test.lastIndexOf(this.reference.get(index)));
+		}
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		count = rnd.nextInt(this.reference.size()/4)+1;
+		int minIndex = Integer.MAX_VALUE;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex) minIndex = index;
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex)
+				assertEquals(index, test.lastIndexOf(this.reference.get(index)));
+			else
+				assertFalse(index==test.lastIndexOf(this.reference.get(index)));
+		}
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size());
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(index, test.lastIndexOf(this.reference.get(index)));
+		}
+	}
+
+	public void testGetInt() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        // Test the content
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(this.reference.get(index), test.get(index));
+		}
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		count = rnd.nextInt(this.reference.size()/4)+1;
+		int minIndex = Integer.MAX_VALUE;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex) minIndex = index;
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size())+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			if (index<minIndex)
+				assertEquals(this.reference.get(index), test.get(index));
+			else
+				assertFalse(this.reference.get(index)==test.get(index));
+		}
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		count = rnd.nextInt(this.reference.size());
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			assertEquals(this.reference.get(index), test.get(index));
+		}
+		
+		assertException(test, "get", new Class<?>[] {int.class}, new Object[] {test.size()}); //$NON-NLS-1$
+	}
+	
+	public void testAddE() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+        
+        // Add an element
+        String newElement = randomString();
+        this.reference.add(newElement);
+        test.add(newElement);
+        assertEquals(this.reference, test);
+        newElement = null;
+
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		Random rnd = new Random();
+		int index, count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+		// Test content
+        assertNotEquals(this.reference, test);
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+		// Test content
+        assertEquals(this.reference, test);
+        
+        // Add a string without reference
+        newElement = randomString();
+        test.add(newElement);
+        newElement = null;
+        
+		// Collects the objects
+		collect();
+		
+		// Test content
+        assertEquals(this.reference, test);        
+	}
+
+	public void testAddIntE() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+        
+        Random rnd = new Random();
+        int index, testCount, count;
+        String newElement, msg;
+        
+        testCount = rnd.nextInt(20)+5;
+        
+        for(int i=0; i<testCount; i++) {
+        	msg = "test "+(i+1)+"/"+testCount; //$NON-NLS-1$ //$NON-NLS-2$
+        	
+	        // Add an element
+	        newElement = randomString(10);
+	        index = rnd.nextInt(this.reference.size());
+	        this.reference.add(index, newElement);
+	        test.add(index, newElement);
+	        newElement = null;
+
+	        // Test elements
+	        assertEquals(msg,this.reference, test);	
+	
+	        // Remove elements
+			ArrayList<String> removedElements = new ArrayList<String>();
+			count = rnd.nextInt(this.reference.size()/4)+1;
+			for(int j=0; j<count; j++) {
+				index = rnd.nextInt(this.reference.size());
+				removedElements.add(this.reference.remove(index));			
+			}
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+	
+			// Clear the list of removed elements, which will cause collecting
+			removedElements.clear();
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertEquals(msg,this.reference, test);
+	        
+	        // Add a string without reference
+	        newElement = randomString(10);
+	        index = rnd.nextInt(test.size());
+	        test.add(index, newElement);
+	        newElement = null;
+	        
+			// Collects the objects
+			collect();
+			
+			// Test content
+	        assertEquals(msg,this.reference, test);
+	        
+        }
+	}
+
+	public void testAddAllCollection() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+        
+        // Add a set of elements
+        ArrayList<String> newElements = new ArrayList<String>();
+		Random rnd = new Random();
+        int count =  rnd.nextInt(20)+5;
+        for(int i=0; i<count; i++)
+        	newElements.add(randomString(10));
+        this.reference.addAll(newElements);
+        test.addAll(newElements);
+        assertEquals(this.reference, test);
+        newElements.clear();
+        newElements = null;
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		int index;
+		count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+		// Test content
+        assertNotEquals(this.reference, test);
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+		// Test content
+        assertEquals(this.reference, test);
+        
+        // Add a string without reference
+        count =  rnd.nextInt(20)+5;
+        for(int i=0; i<count; i++)
+        	test.add(randomString(10));
+        
+		// Collects the objects
+		collect();
+		
+		// Test content
+        assertEquals(this.reference, test);        
+	}
+
+	public void testAddAllIntCollection() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        String msg;
+		Random rnd = new Random();
+        int testCount = rnd.nextInt(20)+5;
+        int index, count, insertionIndex;
+        ArrayList<String> newElements;
+        
+        for(int i=0; i<testCount; i++) {
+        	msg = "test "+(i+1)+"/"+testCount; //$NON-NLS-1$ //$NON-NLS-2$
+	        insertionIndex = rnd.nextInt(this.reference.size());
+
+	        // Add a set of elements
+	        newElements = new ArrayList<String>();
+	        count =  rnd.nextInt(20)+5;
+	        for(int j=0; j<count; j++) {
+	        	newElements.add(randomString(10));
+	        }
+	        this.reference.addAll(insertionIndex,newElements);
+	        test.addAll(insertionIndex,newElements);
+	        newElements.clear();
+	        newElements = null;
+	        assertEquals(msg,this.reference, test);
+	
+	        // Remove elements
+			ArrayList<String> removedElements = new ArrayList<String>();
+			count = rnd.nextInt(this.reference.size()/4)+1;
+			for(int j=0; j<count; j++) {
+				index = rnd.nextInt(this.reference.size());
+				removedElements.add(this.reference.remove(index));			
+			}
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+	
+			// Clear the list of removed elements, which will cause collecting
+			removedElements.clear();
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertEquals(msg,this.reference, test);
+	        
+	        // Add a string without reference
+	        count =  rnd.nextInt(20)+5;
+	        for(int j=0; j<count; j++)
+	        	test.add(randomString(10));
+	        
+			// Collects the objects
+			collect();
+			
+			// Test content
+	        assertEquals(msg,this.reference, test);
+        }
+	}
+
+	public void testSetIntE() {
+        String msg;
+		Random rnd = new Random();
+        int testCount = rnd.nextInt(20)+5;
+        int index, count, insertionIndex;
+        
+        for(int i=0; i<testCount; i++) {
+        	msg = "test "+(i+1)+"/"+testCount; //$NON-NLS-1$ //$NON-NLS-2$
+        	spawnReference();
+        	insertionIndex = rnd.nextInt(this.reference.size());
+
+	        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+	        test.setDeeplyExpurge(true);
+	        assertEquals(this.reference, test);
+        	
+	        // Add an element
+	        String newElement = randomString();
+	        this.reference.set(insertionIndex,newElement);
+	        test.set(insertionIndex,newElement);
+	        newElement = null;
+	        assertEquals(msg,this.reference, test);
+	
+	
+	        // Remove elements
+			ArrayList<String> removedElements = new ArrayList<String>();
+			rnd = new Random();
+			count = rnd.nextInt(this.reference.size()/4+1)+1;
+			for(int j=0; j<count; j++) {
+				index = rnd.nextInt(this.reference.size());
+				removedElements.add(this.reference.remove(index));			
+			}
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+	
+			// Clear the list of removed elements, which will cause collecting
+			removedElements.clear();
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertEquals(msg,this.reference, test);
+	        
+	        // Add a string without reference
+	        if (!test.isEmpty()) {
+		        newElement = randomString();
+		        insertionIndex = rnd.nextInt(test.size());
+		        test.set(insertionIndex,newElement);
+		        newElement = null;
+	        }
+	        
+			// Collects the objects
+			collect();
+			
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+        }
+	}
+
+	public void testRemoveObject() {
+        String msg;
+		Random rnd = new Random();
+        int testCount = rnd.nextInt(20)+5;
+        int removalIndex;
+        
+        for(int i=0; i<testCount; i++) {
+        	msg = "test "+(i+1)+"/"+testCount; //$NON-NLS-1$ //$NON-NLS-2$
+        	spawnReference();
+        	removalIndex = rnd.nextInt(this.reference.size());
+
+	        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+	        test.setDeeplyExpurge(true);
+	        assertEquals(this.reference, test);
+        	
+	        // Remove elements
+	        test.remove(this.reference.get(removalIndex));
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+	
+			// Clear the list of removed elements, which will cause collecting
+			this.reference.remove(removalIndex);
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertEquals(msg,this.reference, test);
+        }
+	}
+
+	public void testRemoveInt() {
+        String msg;
+		Random rnd = new Random();
+        int testCount = rnd.nextInt(20)+5;
+        int removalIndex;
+        
+        for(int i=0; i<testCount; i++) {
+        	msg = "test "+(i+1)+"/"+testCount; //$NON-NLS-1$ //$NON-NLS-2$
+        	spawnReference();
+        	removalIndex = rnd.nextInt(this.reference.size());
+
+	        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+	        test.setDeeplyExpurge(true);
+	        assertEquals(this.reference, test);
+        	
+	        // Remove elements
+	        test.remove(removalIndex);
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertNotEquals(msg,this.reference, test);
+	
+			// Clear the list of removed elements, which will cause collecting
+			this.reference.remove(removalIndex);
+	
+			// Collects the objects
+			collect();
+	
+			// Test content
+	        assertEquals(msg,this.reference, test);
+        }
+	}
+
+	public void testHashCode() {
+        WeakArrayList<String> test = new WeakArrayList<String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference, test);
+
+        assertEquals(this.reference.hashCode(),test.hashCode());
+
+        // Remove elements
+		ArrayList<String> removedElements = new ArrayList<String>();
+		Random rnd = new Random();
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		for(int i=0; i<count; i++) {
+			int index = rnd.nextInt(this.reference.size());
+			removedElements.add(this.reference.remove(index));			
+		}
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+        assertNotEquals(this.reference.hashCode(), test.hashCode());
+
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+        assertEquals(this.reference.hashCode(), test.hashCode());
+    }
+    
+}

Added: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueMapTest.java	                        (rev 0)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueMapTest.java	2009-02-02 20:43:13 UTC (rev 28)
@@ -0,0 +1,357 @@
+package org.arakhne.util.ref;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Random;
+import java.util.Map.Entry;
+
+import org.arakhne.junit.AbstractTestCase;
+
+public class WeakValueMapTest extends AbstractTestCase {
+
+	private static final int REFERENCE_SIZE = 0; 
+	
+	private final HashMap<String,String> reference = new HashMap<String,String>();
+	
+	private static void collect() {
+		System.gc();System.gc();System.gc();
+	}
+	
+	private void spawnReference() {
+		this.reference.clear();
+		Random rnd = new Random();
+		int count = rnd.nextInt(REFERENCE_SIZE+1)+5;
+		String str;
+		for(int i=0; i<count; i++) {
+			str = randomString(10);
+			this.reference.put(
+					Integer.toString(i)+str,
+					str);
+		}
+		str = null;
+	}
+	
+	private String getReferenceObject(int index) {
+		Object[] tab = this.reference.keySet().toArray();
+		return (String)tab[index];
+	}
+	
+	private Map<String,String> removeElementsFromReference() {
+		HashMap<String,String> removed = new HashMap<String,String>();
+		Random rnd = new Random();
+		int index;
+		int count = rnd.nextInt(this.reference.size()/4)+1;
+		String key, value;
+		for(int i=0; i<count; i++) {
+			index = rnd.nextInt(this.reference.size());
+			key = getReferenceObject(index);
+			value = this.reference.remove(key);
+			removed.put(key,value);
+		}
+		key = null;
+		value =  null;
+		return removed;
+	}
+	
+	@Override
+	public void setUp() {
+		spawnReference();
+	}
+	
+	@Override
+	public void tearDown() {
+		this.reference.clear();
+	}
+	
+	public void testWeakValueMapMap() {
+        WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        assertDeepSimilars(this.reference, test);
+    }
+
+    public void testSize() {
+        WeakValueMap<String,String> test = new WeakValueMap<String,String>();
+        assertEquals(0, test.size());
+        
+        test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertEquals(this.reference.size(), test.size());
+
+        removeElementsFromReference();
+		
+		collect();
+		
+        assertEquals(this.reference.size(), test.size());		
+    }
+
+    public void testIsEmpty() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>();
+        assertTrue(test.isEmpty());
+        
+        test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertFalse(test.isEmpty());
+        
+        removeElementsFromReference();
+
+		collect();
+		
+        assertFalse(test.isEmpty());
+        
+        this.reference.clear();
+
+		collect();
+		
+        assertTrue(test.isEmpty());
+    }
+	
+    public void testContainsKey() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertDeepSimilars(this.reference, test);
+
+        // Test the content
+		{
+			String elt;
+			Iterator<String> iter = this.reference.keySet().iterator(); 
+			while (iter.hasNext()) {
+				elt = iter.next();
+				assertTrue(test.containsKey(elt));
+			}
+			elt = null;
+		}
+		assertDeepSimilars(this.reference, test);
+
+        Map<String,String> removedElements = removeElementsFromReference();
+        int originalSize = removedElements.size() + this.reference.size();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+		assertNotDeepSimilars(this.reference, test);
+		
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+		removedElements = null;
+
+		// Collects the objects
+		collect();
+		
+        // Test the content
+		assertEquals(this.reference.size(), test.size());
+		assertDeepSimilars(this.reference, test);
+		for(String elt : this.reference.keySet()) {
+			assertTrue(test.containsKey(elt));
+		}
+    }
+
+    public void testContainsValue() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+        assertDeepSimilars(this.reference, test);
+
+        // Test the content
+		{
+			String elt;
+			Iterator<String> iter = this.reference.values().iterator(); 
+			while (iter.hasNext()) {
+				elt = iter.next();
+				assertTrue(test.containsValue(elt));
+			}
+			elt = null;
+		}
+		assertDeepSimilars(this.reference, test);
+
+        Map<String,String> removedElements = removeElementsFromReference();
+        int originalSize = removedElements.size() + this.reference.size();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+		assertEquals(originalSize, test.size());
+		assertNotDeepSimilars(this.reference, test);
+		
+		// Clear the list of removed elements, which will cause collecting
+		removedElements.clear();
+		removedElements = null;
+
+		// Collects the objects
+		collect();
+		
+        // Test the content
+		assertEquals(this.reference.size(), test.size());
+		assertDeepSimilars(this.reference, test);
+		for(String elt : this.reference.values()) {
+			assertTrue(test.containsValue(elt));
+		}
+    }
+
+    public void testEntryIterator() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertTrue(this.reference.containsKey(e.getKey()));
+        		assertEquals(this.reference.get(e.getKey()),this.reference.get(e.getKey()));
+        	}
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+    		assertNotDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertTrue(baseElements.containsKey(e.getKey()));
+        		assertEquals(baseElements.get(e.getKey()),baseElements.get(e.getKey()));
+        	}
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		Entry<String,String> e;
+        	Iterator<Entry<String,String>> iter = test.entrySet().iterator();
+        	while (iter.hasNext()) {
+        		e = iter.next();
+        		assertTrue(this.reference.containsKey(e.getKey()));
+        		assertEquals(this.reference.get(e.getKey()),this.reference.get(e.getKey()));
+        	}
+    	}
+    }
+
+    public void testKeyIterator() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String k;
+        	Iterator<String> iter = test.keySet().iterator();
+        	while (iter.hasNext()) {
+        		k = iter.next();
+        		assertTrue(this.reference.containsKey(k));
+        	}
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    		String k;
+        	Iterator<String> iter = test.keySet().iterator();
+        	while (iter.hasNext()) {
+        		k = iter.next();
+        		assertTrue(baseElements.containsKey(k));
+        	}
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String k;
+        	Iterator<String> iter = test.keySet().iterator();
+        	while (iter.hasNext()) {
+        		k = iter.next();
+        		assertTrue(this.reference.containsKey(k));
+        	}
+    	}
+    }
+
+    public void testValueIterator() {
+    	WeakValueMap<String,String> test = new WeakValueMap<String,String>(this.reference);
+        test.setDeeplyExpurge(true);
+	
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String v;
+        	Iterator<String> iter = test.values().iterator();
+        	while (iter.hasNext()) {
+        		v = iter.next();
+        		assertTrue(this.reference.containsValue(v));
+        	}
+        	v = null;
+        	iter = null;
+    	}
+
+        // Remove elements
+    	Map<String,String> baseElements = new HashMap<String,String>(this.reference);
+        removeElementsFromReference();
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertNotDeepSimilars(this.reference, test);
+    		String v;
+        	Iterator<String> iter = test.values().iterator();
+        	while (iter.hasNext()) {
+        		v = iter.next();
+        		assertTrue(baseElements.containsValue(v));
+        	}
+        	v = null;
+        	iter = null;
+    	}
+
+		// Clear the list of removed elements, which will cause collecting
+		baseElements.clear();
+		baseElements = null;
+
+		// Collects the objects
+		collect();
+
+        // Test the content
+    	{
+        	assertDeepSimilars(this.reference, test);
+    		String v;
+        	Iterator<String> iter = test.values().iterator();
+        	while (iter.hasNext()) {
+        		v = iter.next();
+        		assertTrue(this.reference.containsValue(v));
+        	}
+        	v = null;
+        	iter = null;
+    	}
+    }
+
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/