Author: davidb
Date: Thu Sep 22 15:38:48 2016
New Revision: 1761973

URL: http://svn.apache.org/viewvc?rev=1761973&view=rev
Log:
Felix Converter Service - migrate adapter to builder pattern

Added:
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
    
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/ConverterBuilder.java
Removed:
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Activator.java
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterService.java
    
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Adapter.java
Modified:
    felix/trunk/converter/converter/pom.xml
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
    
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Converter.java
    
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/StandardConverter.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/AdapterTest.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
    
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java

Modified: felix/trunk/converter/converter/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/pom.xml?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- felix/trunk/converter/converter/pom.xml (original)
+++ felix/trunk/converter/converter/pom.xml Thu Sep 22 15:38:48 2016
@@ -65,7 +65,6 @@
                 </executions>
                 <configuration>
                     <instructions>
-                        
<Bundle-Activator>org.apache.felix.converter.impl.Activator</Bundle-Activator>
                         
<Private-Package>org.apache.felix.converter.*</Private-Package>
                         
<Export-Package>org.osgi.service.converter</Export-Package>
                         <Import-Package>org.osgi.service.converter, 
*</Import-Package>

Modified: 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
 Thu Sep 22 15:38:48 2016
@@ -28,22 +28,25 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.osgi.service.converter.Adapter;
 import org.osgi.service.converter.ConversionException;
 import org.osgi.service.converter.ConvertFunction;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.ConverterBuilder;
 import org.osgi.service.converter.Converting;
 import org.osgi.service.converter.Function;
 import org.osgi.service.converter.Rule;
 import org.osgi.service.converter.TypeReference;
 
-public class AdapterImpl implements Adapter, InternalConverter {
+public class AdapterImpl implements InternalConverter {
     private final InternalConverter delegate;
     private final Map<TypePair, ConvertFunction<Object, Object>> classRules =
             new ConcurrentHashMap<>();
 
-    AdapterImpl(InternalConverter converter) {
+    AdapterImpl(InternalConverter converter, List<Rule<?,?>> rules) {
         this.delegate = converter;
+        for (Rule<?,?> r : rules) {
+            rule(r);
+        }
     }
 
     @Override
@@ -54,13 +57,13 @@ public class AdapterImpl implements Adap
     }
 
     @Override
-    public Adapter newAdapter() {
-        return new AdapterImpl(this);
+    public ConverterBuilder newConverterBuilder() {
+        return new ConverterBuilderImpl(this);
     }
 
-    @Override
+    /*
     @SuppressWarnings("unchecked")
-    public <F, T> Adapter rule(Class<F> fromCls, Class<T> toCls,
+    public <F, T> AdapterImpl rule(Class<F> fromCls, Class<T> toCls,
             Function<F, T> toFun, Function<T, F> fromFun) {
         if (fromCls.equals(toCls))
             throw new IllegalArgumentException();
@@ -77,23 +80,21 @@ public class AdapterImpl implements Adap
         return this;
     }
 
-    @Override
-    public <F, T> Adapter rule(TypeReference<F> fromRef, TypeReference<T> 
toRef,
+    public <F, T> AdapterImpl rule(TypeReference<F> fromRef, TypeReference<T> 
toRef,
             Function<F, T> toFun, Function<T, F> fromFun) {
         // TODO Auto-generated method stub
         return null;
     }
 
-    @Override
-    public <F, T> Adapter rule(Type fromType, Type toType,
+    public <F, T> AdapterImpl rule(Type fromType, Type toType,
             Function<F, T> toFun, Function<T, F> fromFun) {
         // TODO Auto-generated method stub
         return null;
     }
+    */
 
-    @Override
     @SuppressWarnings("unchecked")
-    public <F, T> Adapter rule(Rule<F, T> rule) {
+    private <F, T> AdapterImpl rule(Rule<F, T> rule) {
         ConvertFunction<F, T> toFun = rule.getToFunction();
         if (toFun != null)
             classRules.put(new TypePair(rule.getFromClass(), 
rule.getToClass()),

Added: 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java?rev=1761973&view=auto
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
 (added)
+++ 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
 Thu Sep 22 15:38:48 2016
@@ -0,0 +1,66 @@
+/*
+ * 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.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.converter.impl.AdapterImpl.ConvertFunctionImpl;
+import org.osgi.service.converter.ConverterBuilder;
+import org.osgi.service.converter.Function;
+import org.osgi.service.converter.Rule;
+import org.osgi.service.converter.TypeReference;
+
+public class ConverterBuilderImpl implements ConverterBuilder {
+    private final InternalConverter adapter;
+    private final List<Rule<?,?>> rules = new ArrayList<>();
+
+    public ConverterBuilderImpl(InternalConverter a) {
+        this.adapter = a;
+    }
+
+    @Override
+    public InternalConverter build() {
+        return new AdapterImpl(adapter, rules);
+    }
+
+    @Override
+    public <F, T> ConverterBuilder rule(Rule<F, T> rule) {
+        rules.add(rule);
+        return this;
+    }
+
+    @Override
+    public <F, T> ConverterBuilder rule(Class<F> fromCls, Class<T> toCls, 
Function<F, T> toFun, Function<T, F> fromFun) {
+        rules.add(new Rule<F, T>(fromCls, toCls, new 
ConvertFunctionImpl<>(toFun), new ConvertFunctionImpl<>(fromFun)));
+        return this;
+    }
+
+    @Override
+    public <F, T> ConverterBuilder rule(TypeReference<F> fromRef, 
TypeReference<T> toRef, Function<F, T> toFun,
+            Function<T, F> fromFun) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public <F, T> ConverterBuilder rule(Type fromType, Type toType, 
Function<F, T> toFun, Function<T, F> fromFun) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Modified: 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
 Thu Sep 22 15:38:48 2016
@@ -25,20 +25,15 @@ import java.time.ZonedDateTime;
 import java.util.UUID;
 import java.util.regex.Pattern;
 
-import org.osgi.service.converter.Adapter;
+import org.osgi.service.converter.ConverterBuilder;
 
 public class ConverterImpl implements InternalConverter {
     @Override
-    public Adapter newAdapter() {
-        return new AdapterImpl(this);
-    }
-
-    @Override
     public InternalConverting convert(Object obj) {
         return new ConvertingImpl(this, obj);
     }
 
-    public void addStandardRules(Adapter a) {
+    public void addStandardRules(ConverterBuilder a) {
         a.rule(Byte.class, String.class, v -> v.toString(), Byte::parseByte); 
// TODO test
         a.rule(Character.class, Boolean.class, v -> v.charValue() != 0,
                 v -> v.booleanValue() ? (char) 1 : (char) 0);
@@ -60,4 +55,9 @@ public class ConverterImpl implements In
         a.rule(UUID.class, String.class, UUID::toString, UUID::fromString);
         a.rule(ZonedDateTime.class, String.class, ZonedDateTime::toString, 
ZonedDateTime::parse);
     }
+
+    @Override
+    public ConverterBuilderImpl newConverterBuilder() {
+        return new ConverterBuilderImpl(this);
+    }
 }

Modified: 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Converter.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Converter.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Converter.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/Converter.java
 Thu Sep 22 15:38:48 2016
@@ -36,13 +36,10 @@ public interface Converter {
        Converting convert(Object obj);
 
        /**
-        * Obtain a new adapter to this converter. The adapter behaves just 
like the
-        * converter except for the exception rules registered with is. It is 
also
-        * possible to obtain a new Adapter for an existing adapter. This 
allows for
-        * adding an additional layer of rules over an existing adapter. For 
more
-        * details see the {@link Adapter} interface.
+        * Obtain a builder to create a modified converter based on this 
converter.
+     * For more details see the {@link ConverterBuilder} interface.
         *
-        * @return A new adapter to this converter.
+        * @return A new Converter Builder.
         */
-       Adapter newAdapter();
+       ConverterBuilder newConverterBuilder();
 }

Added: 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/ConverterBuilder.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/ConverterBuilder.java?rev=1761973&view=auto
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/ConverterBuilder.java
 (added)
+++ 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/ConverterBuilder.java
 Thu Sep 22 15:38:48 2016
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) OSGi Alliance (2016). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.converter;
+
+import java.lang.reflect.Type;
+
+/**
+ * A builder to create a new converter with modified behaviour based on an 
existing
+ * converter. The modified behaviour is specified by providing rules and/or
+ * conversion functions.
+ *
+ * @author $Id$
+ */
+public interface ConverterBuilder {
+    /**
+     * Build the specified converter.
+     *
+     * @return A new converter with the rules provided to the builder.
+     */
+    Converter build();
+
+    /**
+     * Register a special rule for this converter.
+     *
+     * @param rule The rule
+     * @return This converter builder for further building.
+     */
+    <F, T> ConverterBuilder rule(Rule<F,T> rule);
+
+    /**
+     * Register a special rule for this converter.
+     *
+     * @param fromCls The class from which to convert.
+     * @param toCls The class to which to convert.
+     * @param toFun A function that handles the conversion.
+     * @param fromFun A function that handles the reverse conversion.
+     * @return This converter builder for further building.
+     */
+    <F, T> ConverterBuilder rule(Class<F> fromCls, Class<T> toCls,
+            Function<F,T> toFun,
+            Function<T,F> fromFun);
+
+    /**
+     * Register a special rule for this converter.
+     *
+     * @param fromRef A type reference representing the class to convert from.
+     * @param toRef A type reference representing the class to convert to.
+     * @param toFun A function that handles the conversion.
+     * @param fromFun A function that handles the reverse conversion.
+     * @return This converter builder for further building.
+     */
+    <F, T> ConverterBuilder rule(TypeReference<F> fromRef, TypeReference<T> 
toRef,
+            Function<F,T> toFun,
+            Function<T,F> fromFun);
+
+    /**
+     * Register a special rule for this converter.
+     *
+     * @param fromType A reflection type from which to convert.
+     * @param toType A reflection type to which to convert.
+     * @param toFun A function that handles the conversion.
+     * @param fromFun A function that handles the reverse conversion.
+     * @return This converter builder for further building.
+     */
+    <F, T> ConverterBuilder rule(Type fromType, Type toType,
+            Function<F,T> toFun,
+            Function<T,F> fromFun);
+}

Modified: 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/StandardConverter.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/StandardConverter.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/StandardConverter.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/osgi/service/converter/StandardConverter.java
 Thu Sep 22 15:38:48 2016
@@ -16,25 +16,27 @@
  */
 package org.osgi.service.converter;
 
+import org.apache.felix.converter.impl.ConverterBuilderImpl;
 import org.apache.felix.converter.impl.ConverterImpl;
+import org.apache.felix.converter.impl.InternalConverter;
 
 public class StandardConverter implements Converter {
-    private final Adapter adapter;
+    private final InternalConverter converter;
 
     public StandardConverter() {
         ConverterImpl impl = new ConverterImpl();
-        Adapter a = impl.newAdapter();
-        impl.addStandardRules(a);
-        adapter = a;
+        ConverterBuilderImpl cb = impl.newConverterBuilder();
+        impl.addStandardRules(cb);
+        converter = cb.build();
     }
 
     @Override
     public Converting convert(Object obj) {
-        return adapter.convert(obj);
+        return converter.convert(obj);
     }
 
     @Override
-    public Adapter newAdapter() {
-        return adapter.newAdapter();
+    public ConverterBuilder newConverterBuilder() {
+        return converter.newConverterBuilder();
     }
 }

Modified: 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/AdapterTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/AdapterTest.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/AdapterTest.java
 (original)
+++ 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/AdapterTest.java
 Thu Sep 22 15:38:48 2016
@@ -30,9 +30,9 @@ import java.util.stream.Stream;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.osgi.service.converter.Adapter;
 import org.osgi.service.converter.ConvertFunction;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.ConverterBuilder;
 import org.osgi.service.converter.Rule;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -53,10 +53,10 @@ public class AdapterTest {
 
     @Test
     public void testStringArrayToStringAdapter() {
-        Adapter ca = converter.newAdapter();
-        ca.rule(String[].class, String.class,
+        ConverterBuilder cb = converter.newConverterBuilder();
+        Converter ca = cb.rule(String[].class, String.class,
                 v -> Stream.of(v).collect(Collectors.joining(",")),
-                v -> v.split(","));
+                v -> v.split(",")).build();
 
         assertEquals("A", converter.convert(new String[] {"A", 
"B"}).to(String.class));
         assertEquals("A,B", ca.convert(new String[] {"A", 
"B"}).to(String.class));
@@ -77,10 +77,10 @@ public class AdapterTest {
 
     @Test
     public void testSecondLevelAdapter() {
-        Adapter ca = converter.newAdapter();
+        ConverterBuilder cb = converter.newConverterBuilder();
 
-        ca.rule(char[].class, String.class, AdapterTest::convertToString, 
null);
-        ca.rule(new Rule<String, Number>(String.class, Number.class, new 
ConvertFunction<String, Number>() {
+        cb.rule(char[].class, String.class, AdapterTest::convertToString, 
null);
+        cb.rule(new Rule<String, Number>(String.class, Number.class, new 
ConvertFunction<String, Number>() {
             @Override
             public Number convert(String obj, Type targetType) throws 
Exception {
                 if (Integer.class.equals(targetType))
@@ -90,30 +90,29 @@ public class AdapterTest {
                 return null;
             }
         }));
+        Converter ca = cb.build();
 
         assertEquals("hi", ca.convert(new char[] {'h', 'i'}).to(String.class));
         assertEquals(Integer.valueOf(-1), 
ca.convert("Hello").to(Integer.class));
         assertEquals(Long.valueOf(-1), ca.convert("Hello").to(Long.class));
 
-        Adapter ca2 = ca.newAdapter();
         // Shadow the Integer variant but keep Long going to the Number 
variant.
-        ca2.rule(String.class, Integer.class, v -> v.length(), null);
+        Converter ca2 = ca.newConverterBuilder().rule(String.class, 
Integer.class, v -> v.length(), null).build();
         assertEquals(5, (int) ca2.convert("Hello").to(Integer.class));
         assertEquals(Long.valueOf(-1), ca2.convert("Hello").to(Long.class));
     }
 
     @Test
     public void testCannotHandleSpecific() {
-        Adapter ca = converter.newAdapter();
-
-        ca.rule(new Rule<Integer, Long>(Integer.class, Long.class, new 
ConvertFunction<Integer,Long>() {
+        Converter ca = converter.newConverterBuilder().rule(
+                new Rule<Integer, Long>(Integer.class, Long.class, new 
ConvertFunction<Integer,Long>() {
             @Override
             public Long convert(Integer obj, Type targetType) throws Exception 
{
                 if (obj.intValue() != 1)
                     return new Long(-obj.intValue());
                 return null;
             }
-        }));
+        })).build();
 
         assertEquals(Long.valueOf(-2), 
ca.convert(Integer.valueOf(2)).to(Long.class));
 
@@ -138,9 +137,10 @@ public class AdapterTest {
         Rule<Object, Object> allCatch = new Rule<>(Object.class, Object.class,
                 (v,t) -> v.toString());
 
-        Adapter ca = converter.newAdapter();
-        ca.rule(r);
-        ca.rule(allCatch);
+        ConverterBuilder cb = converter.newConverterBuilder();
+        cb.rule(r);
+        cb.rule(allCatch);
+        Converter ca = cb.build();
 
         assertEquals(3L, (long) ca.convert(Arrays.asList("a", "b", 
"c")).to(Long.class));
         assertEquals(3, (long) ca.convert(Arrays.asList("a", "b", 
"c")).to(Integer.class));
@@ -159,10 +159,11 @@ public class AdapterTest {
         Rule<Object, Object> allCatch = new Rule<>(Object.class, Object.class,
                 (v,t) -> {snooped.put(v,t); return null;}, null);
 
-        Adapter ca = converter.newAdapter();
-        ca.rule(r);
-        ca.rule(r2);
-        ca.rule(allCatch);
+        ConverterBuilder cb = converter.newConverterBuilder();
+        cb.rule(r);
+        cb.rule(r2);
+        cb.rule(allCatch);
+        Converter ca = cb.build();
 
         assertEquals("Precondition", 0, snooped.size());
         assertEquals("arraylist", ca.convert(

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=1761973&r1=1761972&r2=1761973&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
 Thu Sep 22 15:38:48 2016
@@ -27,6 +27,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.TypeReference;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -42,7 +43,7 @@ public class ConverterMapTest {
 
     @Before
     public void setUp() {
-        converter = new ConverterService();
+        converter = new StandardConverter();
     }
 
     @After

Modified: 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
 (original)
+++ 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
 Thu Sep 22 15:38:48 2016
@@ -48,8 +48,10 @@ import org.apache.felix.converter.impl.M
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.osgi.service.converter.Adapter;
 import org.osgi.service.converter.ConversionException;
+import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.ConverterBuilder;
+import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.TypeReference;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -63,11 +65,11 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 public class ConverterServiceTest {
-    private ConverterService converter;
+    private Converter converter;
 
     @Before
     public void setUp() {
-        converter = new ConverterService();
+        converter = new StandardConverter();
     }
 
     @After
@@ -302,23 +304,23 @@ public class ConverterServiceTest {
 
     @Test
     public void testCustomStringArrayConverstion() {
-        Adapter adapter = converter.newAdapter();
-        adapter.rule(String[].class, String.class,
+        ConverterBuilder cb = converter.newConverterBuilder();
+        cb.rule(String[].class, String.class,
                 v -> Stream.of(v).collect(Collectors.joining(",")),
                 v -> v.split(","));
+        Converter adapted = cb.build();
 
         String[] sa = {"A", "B"};
-        assertEquals("A,B", adapter.convert(sa).to(String.class));
-        assertArrayEquals(sa, adapter.convert("A,B").to(String[].class));
+        assertEquals("A,B", adapted.convert(sa).to(String.class));
+        assertArrayEquals(sa, adapted.convert("A,B").to(String[].class));
     }
 
     @Test
     public void testUUIDConversion() {
-        ConverterService cs = new ConverterService();
         UUID uuid = UUID.randomUUID();
-        String s = cs.convert(uuid).to(String.class);
+        String s = converter.convert(uuid).to(String.class);
         assertTrue("UUID should be something", s.length() > 0);
-        UUID uuid2 = cs.convert(s).to(UUID.class);
+        UUID uuid2 = converter.convert(s).to(UUID.class);
         assertEquals(uuid, uuid2);
     }
 

Modified: 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java?rev=1761973&r1=1761972&r2=1761973&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
 (original)
+++ 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
 Thu Sep 22 15:38:48 2016
@@ -26,7 +26,6 @@ import org.apache.sling.commons.json.JSO
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.osgi.service.converter.Adapter;
 import org.osgi.service.converter.Converter;
 import org.osgi.service.converter.StandardConverter;
 
@@ -82,8 +81,8 @@ public class JsonSerializerTest {
         Map<String, Object> m = new HashMap<>();
         m.put("submap", m1);
 
-        Adapter ca = converter.newAdapter();
-        ca.rule(Foo.class, String.class, Foo::tsFun, v -> Foo.fsFun(v));
+        Converter ca = converter.newConverterBuilder().
+                rule(Foo.class, String.class, Foo::tsFun, v -> 
Foo.fsFun(v)).build();
 
         JsonSerializerImpl jsonCodec = new JsonSerializerImpl();
         String json = jsonCodec.serialize(m).with(ca).toString();


Reply via email to