You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2017/08/28 15:52:27 UTC
svn commit: r1806468 - in /felix/trunk/converter/converter/src:
main/java/org/apache/felix/converter/impl/ConvertingImpl.java
test/java/org/apache/felix/converter/impl/ConverterMapTest.java
test/java/org/apache/felix/converter/impl/TestDictionary.java
Author: davidb
Date: Mon Aug 28 15:52:27 2017
New Revision: 1806468
URL: http://svn.apache.org/viewvc?rev=1806468&view=rev
Log:
Felix Converter - fix conversions from Dictionary objects that don't also implement Map.
Added:
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/TestDictionary.java
Modified:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1806468&r1=1806467&r2=1806468&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java Mon Aug 28 15:52:27 2017
@@ -788,7 +788,7 @@ public class ConvertingImpl extends Abst
if (Map.class.isAssignableFrom(sourceCls) || (DTOUtil.isDTOType(sourceCls) && obj instanceof Map))
return (Map<?,?>) obj;
else if (Dictionary.class.isAssignableFrom(sourceCls))
- return null; // TODO
+ return MapDelegate.forDictionary((Dictionary<?,?>) object, this);
else if (DTOUtil.isDTOType(sourceCls) || sourceAsDTO)
return createMapFromDTO(obj, converter);
else if (sourceAsJavaBean) {
Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java?rev=1806468&r1=1806467&r2=1806468&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java (original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java Mon Aug 28 15:52:27 2017
@@ -475,6 +475,23 @@ public class ConverterMapTest {
assertEquals("111", converter.convert(e1).to(Bar.class).value);
}
+ @Test
+ public void testDictionaryToAnnotation() {
+ Dictionary<String, Object> dict = new TestDictionary<>();
+ dict.put("foo", "hello");
+ TestAnnotation ta = converter.convert(dict).to(TestAnnotation.class);
+ assertEquals("hello", ta.foo());
+ }
+
+ @Test
+ public void testDictionaryToMap() {
+ Dictionary<String, Object> dict = new TestDictionary<>();
+ dict.put("foo", "hello");
+ @SuppressWarnings("rawtypes")
+ Map m = converter.convert(dict).copy().to(Map.class);
+ assertEquals("hello", m.get("foo"));
+ }
+
private <K,V> Map.Entry<K,V> getMapEntry(Map<K,V> map) {
assertEquals("This method assumes a map of size 1", 1, map.size());
return map.entrySet().iterator().next();
Added: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/TestDictionary.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/TestDictionary.java?rev=1806468&view=auto
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/TestDictionary.java (added)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/TestDictionary.java Mon Aug 28 15:52:27 2017
@@ -0,0 +1,64 @@
+/*
+ * 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.felix.converter.impl;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/** This test Dictionary does not implement Map. It is used to test cases
+ * where a Dictionary is needed and one that does not implement map needs
+ * to be tested.
+ */
+public class TestDictionary<K,V> extends Dictionary<K,V> {
+ private Hashtable<K,V> delegate = new Hashtable<>();
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public Enumeration<K> keys() {
+ return delegate.keys();
+ }
+
+ @Override
+ public Enumeration<V> elements() {
+ return delegate.elements();
+ }
+
+ @Override
+ public V get(Object key) {
+ return delegate.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ return delegate.put(key, value);
+ }
+
+ @Override
+ public V remove(Object key) {
+ return delegate.remove(key);
+ }
+}