You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by gn...@apache.org on 2009/04/13 20:41:05 UTC
svn commit: r764554 - in /geronimo/xbean/trunk/xbean-reflect/src:
main/java/org/apache/xbean/recipe/MapRecipe.java
test/java/org/apache/xbean/recipe/MapRecipeTest.java
Author: gnodet
Date: Mon Apr 13 18:41:05 2009
New Revision: 764554
URL: http://svn.apache.org/viewvc?rev=764554&view=rev
Log:
Fix MapRecipe
Added:
geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/MapRecipeTest.java
Modified:
geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java?rev=764554&r1=764553&r2=764554&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java (original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java Mon Apr 13 18:41:05 2009
@@ -196,17 +196,17 @@
// if expectedType is a subclass of the assigned type,
// we use it assuming it has a default constructor
- if (type.isAssignableFrom(expectedClass) && RecipeHelper.hasDefaultConstructor(expectedClass)) {
- return expectedClass;
+ if (expectedClass.isAssignableFrom(type) && RecipeHelper.hasDefaultConstructor(type)) {
+ return type;
}
}
// no type explicitly set
if (RecipeHelper.hasDefaultConstructor(expectedClass)) {
return expectedClass;
- } else if (expectedClass.isAssignableFrom(SortedMap.class)) {
+ } else if (SortedMap.class.isAssignableFrom(expectedClass)) {
return TreeMap.class;
- } else if (expectedClass.isAssignableFrom(ConcurrentMap.class)) {
+ } else if (ConcurrentMap.class.isAssignableFrom(expectedClass)) {
return ConcurrentHashMap.class;
} else {
return LinkedHashMap.class;
Added: geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/MapRecipeTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/MapRecipeTest.java?rev=764554&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/MapRecipeTest.java (added)
+++ geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/MapRecipeTest.java Mon Apr 13 18:41:05 2009
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xbean.recipe;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.HashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MapRecipeTest extends TestCase {
+
+ public void testMap() throws Exception {
+ assertEquals(LinkedHashMap.class, new MapRecipe().create(Map.class, false).getClass());
+ assertEquals(TreeMap.class, new MapRecipe().create(SortedMap.class, false).getClass());
+ assertEquals(ConcurrentHashMap.class, new MapRecipe().create(ConcurrentMap.class, false).getClass());
+ assertEquals(HashMap.class, new MapRecipe(HashMap.class).create(Map.class, false).getClass());
+ }
+}