You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:57:30 UTC
svn commit: r815128 -
/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java
Author: bayard
Date: Tue Sep 15 05:57:30 2009
New Revision: 815128
URL: http://svn.apache.org/viewvc?rev=815128&view=rev
Log:
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions:
------------------------------------------------------------------------
r740150 | mbenson | 2009-02-02 15:24:00 -0800 (Mon, 02 Feb 2009) | 1 line
make all [collections] maps implement IterableMap
------------------------------------------------------------------------
r572176 | skestle | 2007-09-02 15:04:41 -0700 (Sun, 02 Sep 2007) | 1 line
Generified LazySortedMap to fix build errors
------------------------------------------------------------------------
r571381 | skestle | 2007-08-30 22:13:56 -0700 (Thu, 30 Aug 2007) | 1 line
Generified LazyMap
------------------------------------------------------------------------
Modified:
commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java?rev=815128&r1=815127&r2=815128&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazyMap.java Tue Sep 15 05:57:30 2009
@@ -16,14 +16,15 @@
*/
package org.apache.commons.collections.map;
+import static org.apache.commons.collections.map.LazyMap.getLazyMap;
+
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.apache.commons.collections.Factory;
import org.apache.commons.collections.FactoryUtils;
+import org.apache.commons.collections.Transformer;
+import org.junit.Test;
/**
* Extension of {@link AbstractTestMap} for exercising the
@@ -34,56 +35,64 @@
*
* @author Phil Steitz
*/
-public class TestLazyMap extends AbstractTestMap {
-
- protected static final Factory oneFactory = FactoryUtils.constantFactory("One");
- protected static final Factory nullFactory = FactoryUtils.nullFactory();
-
+public class TestLazyMap<K, V> extends AbstractTestIterableMap<K, V> {
+
+ private static final Factory<Integer> oneFactory = FactoryUtils.constantFactory(1);
+
public TestLazyMap(String testName) {
super(testName);
}
-
- public static Test suite() {
- return new TestSuite(TestLazyMap.class);
- }
-
+
public static void main(String args[]) {
String[] testCaseName = { TestLazyMap.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
- //-----------------------------------------------------------------------
- protected Map decorateMap(Map map, Factory factory) {
- return LazyMap.decorate(map, factory);
- }
-
- public Map makeEmptyMap() {
- return decorateMap(new HashMap(), nullFactory);
- }
-
- protected Map makeTestMap(Factory factory) {
- return decorateMap(new HashMap(), factory);
+ @Override
+ public LazyMap<K,V> makeObject() {
+ return getLazyMap(new HashMap<K,V>(), FactoryUtils.<V>nullFactory());
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @Override
public void testMapGet() {
- Map map = makeTestMap(oneFactory);
+ //TODO eliminate need for this via superclass - see svn history.
+ }
+
+ @Test
+ public void mapGetWithFactory() {
+ Map<Integer, Number> map = getLazyMap(new HashMap<Integer,Number>(), oneFactory);
assertEquals(0, map.size());
- String s1 = (String) map.get("Five");
- assertEquals("One", s1);
+ Number i1 = map.get("Five");
+ assertEquals(1, i1);
assertEquals(1, map.size());
- String s2 = (String) map.get(new String(new char[] {'F','i','v','e'}));
- assertEquals("One", s2);
+ Number i2 = map.get(new String(new char[] {'F','i','v','e'}));
+ assertEquals(1, i2);
assertEquals(1, map.size());
- assertSame(s1, s2);
-
- map = makeTestMap(nullFactory);
+ assertSame(i1, i2);
+
+ map = getLazyMap(new HashMap<Integer,Number>(), FactoryUtils.<Long>nullFactory());
Object o = map.get("Five");
assertEquals(null,o);
assertEquals(1, map.size());
-
}
-
+
+ @Test
+ public void mapGetWithTransformer() {
+ Transformer<Number, Integer> intConverter = new Transformer<Number, Integer>(){
+ public Integer transform(Number input) {
+ return input.intValue();
+ }
+ };
+ Map<Long, Number> map = getLazyMap(new HashMap<Long,Number>(), intConverter );
+ assertEquals(0, map.size());
+ Number i1 = map.get(123L);
+ assertEquals(123, i1);
+ assertEquals(1, map.size());
+ }
+
+
+ @Override
public String getCompatibilityVersion() {
return "3.1";
}
@@ -98,4 +107,4 @@
// (java.io.Serializable) map,
// "D:/dev/collections/data/test/LazyMap.fullCollection.version3.1.obj");
// }
-}
\ No newline at end of file
+}