* @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>() {
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) {
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);
}
});
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);
}
});
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);
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);
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);
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);
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);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- config.add(DataSource.class);
+ config.addSetter(DataSource.class);
}
}, IllegalArgumentException.class);
}
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- config.add(String.class);
+ config.addSetter(String.class);
}
}, IllegalArgumentException.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);
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);