(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 15 Nov 2009 11:06:31 +0000 (11:06 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 15 Nov 2009 11:06:31 +0000 (11:06 +0000)
trunk/system/general/src/main/java/org/wamblee/system/adapters/SetterConfiguration.java
trunk/system/general/src/test/java/org/wamblee/system/adapters/SetterConfigurationTest.java

index 15c101dcc1ce9d50a69a93bbb57d5abe9457abb3..57323a54b409531f53667e9d771c4f9d542a0060 100644 (file)
@@ -171,7 +171,7 @@ public class SetterConfiguration {
         * @throws IllegalArgumentException
         *             In case no setter is found or multiple setters are found.
         */
-       public SetterConfiguration add(final Class aType) {
+       public SetterConfiguration addSetter(final Class aType) {
                List<Method> result = new ArrayList<Method>();
                CollectionFilter.filter(getAllSetters(_class, _publicOnly), result,
                                new Condition<Method>() {
@@ -223,11 +223,14 @@ public class SetterConfiguration {
                return result;
        }
 
-       private static ParameterValues createParameterValues(Method method) {
-           // TODO generalize to multiple parameters. 
-               return new ParameterValues(
-                               new String[] { method.getName() }, new Class[] { method
-                                               .getParameterTypes()[0] });
+       private static ParameterValues createParameterValues(Method aMethod) {
+           
+           Class[] paramTypes = aMethod.getParameterTypes();
+           String[] paramNames = new String[paramTypes.length];
+           for (int i = 0; i < paramTypes.length; i++) { 
+               paramNames[i] = aMethod.getName() + "." + i; 
+           } 
+               return new ParameterValues(paramNames, paramTypes);
        }
 
        private static final List<Method> getAllMethods(Class aClass) {
index 34f06a38443df146c4146e162ffec47778fb1e90..aebdc3dffee1d3c742a706432cfcb8dd258b0045 100644 (file)
@@ -36,7 +36,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                config.initAllSetters();
                List<RequiredInterface> required = config.getRequiredInterfaces();
                assertEquals(1, required.size());
-               assertEquals("setValue", required.get(0).getName());
+               assertEquals("setValue.0", required.get(0).getName());
 
                ProvidedInterface provided = new DefaultProvidedInterface("janse",
                                String.class);
@@ -62,8 +62,8 @@ public class SetterConfigurationTest extends AdapterTestCase {
                        }
                });
                assertEquals(2, required.size());
-               assertEquals("setValue", required.get(0).getName());
-               assertEquals("setXyz", required.get(1).getName());
+               assertEquals("setValue.0", required.get(0).getName());
+               assertEquals("setXyz.0", required.get(1).getName());
 
                ProvidedInterface providedString = new DefaultProvidedInterface(
                                "janse", String.class);
@@ -98,9 +98,9 @@ public class SetterConfigurationTest extends AdapterTestCase {
                        }
                });
                assertEquals(3, required.size());
-               assertEquals("setFlag", required.get(0).getName());
-               assertEquals("setValue", required.get(1).getName());
-               assertEquals("setXyz", required.get(2).getName());
+               assertEquals("setFlag.0", required.get(0).getName());
+               assertEquals("setValue.0", required.get(1).getName());
+               assertEquals("setXyz.0", required.get(2).getName());
 
                ProvidedInterface providedBoolean = new DefaultProvidedInterface(
                                "janse", Boolean.class);
@@ -135,8 +135,8 @@ public class SetterConfigurationTest extends AdapterTestCase {
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(2, required.size());
-               assertEquals("setHost", required.get(0).getName());
-               assertEquals("setPort", required.get(1).getName());
+               assertEquals("setHost.0", required.get(0).getName());
+               assertEquals("setPort.0", required.get(1).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -161,7 +161,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                final SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
                List<RequiredInterface> required = config.getRequiredInterfaces();
                assertEquals(1, required.size());
-               assertEquals("setValue", required.get(0).getName());
+               assertEquals("setValue.0", required.get(0).getName());
 
                ProvidedInterface provided = new DefaultProvidedInterface("janse",
                                String.class);
@@ -213,7 +213,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("setHost", required.get(0).getName());
+               assertEquals("setHost.0", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -231,11 +231,11 @@ public class SetterConfigurationTest extends AdapterTestCase {
        
        public void testAddByType() { 
                SetterConfiguration config = new SetterConfiguration(X6.class);
-               config.clear().add(String.class);
+               config.clear().addSetter(String.class);
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("setHost", required.get(0).getName());
+               assertEquals("setHost.0", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -280,7 +280,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
                        @Override
                        public void run() throws Exception {
-                               config.add(DataSource.class);
+                               config.addSetter(DataSource.class);
                        }
                }, IllegalArgumentException.class);
        }
@@ -291,7 +291,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
                        @Override
                        public void run() throws Exception {
-                               config.add(String.class);
+                               config.addSetter(String.class);
                        }
                }, IllegalArgumentException.class);
        }
@@ -302,7 +302,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
                List<RequiredInterface> required = config.getRequiredInterfaces();
                Collections.sort(required, new RequiredInterfaceComparator());
                assertEquals(1, required.size());
-               assertEquals("setHost", required.get(0).getName());
+               assertEquals("setHost.0", required.get(0).getName());
 
                ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                                String.class);
@@ -324,7 +324,7 @@ public class SetterConfigurationTest extends AdapterTestCase {
         List<RequiredInterface> required = config.getRequiredInterfaces();
         Collections.sort(required, new RequiredInterfaceComparator());
         assertEquals(1, required.size());
-        assertEquals("setHost", required.get(0).getName());
+        assertEquals("setHost.0", required.get(0).getName());
 
         ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
                 String.class);