ObjectConfiguration config = new ObjectConfiguration(
PersistentAuthorizationServiceTest.class);
- config.getSetterConfig().clear().add("userAccessor").add(
- "databaseTester").add("hibernateTemplate").add(
- "authorizationService");
+ config.getSetterConfig().clear().add("setUserAccessor").add(
+ "setDatabaseTester").add("setHibernateTemplate").add(
+ "setAuthorizationService");
_container.addComponent("testcase", this, config);
_scope = _container.start();
ObjectConfiguration config = new ObjectConfiguration(
HibernateGroupSetTest.class);
config.getSetterConfig().clear().add(
- "groupSet").add("databaseTester");
+ "setGroupSet").add("setDatabaseTester");
_container.addComponent("testcase", this, config);
_scope = _container.start();
ObjectConfiguration config = new ObjectConfiguration(
HibernateUserAdministrationTest.class);
config.getSetterConfig().clear().add(
- "userCache").add("databaseTester").add("userAdmin");
+ "setUserCache").add("setDatabaseTester").add("setUserAdmin");
_container.addComponent("testcase", this, config);
_scope = _container.start();
ObjectConfiguration config = new ObjectConfiguration(
HibernateUserSetTest.class);
- config.getSetterConfig().clear().add("userset").add(
- "groupset").add("databaseTester").add("userCache");
+ config.getSetterConfig().clear().add("setUserset").add(
+ "setGroupset").add("setDatabaseTester").add("setUserCache");
_container.addComponent("testcase", this, config);
_scope = _container.start();
* Removes a setter from the set of methods.
*
* @param aName
- * Name of the setter to remove (without the "set" prefix).
+ * Name of the setter to remove.
* @return Reference to the current object to allow call chaining.
*/
public SetterConfiguration remove(String aName) {
- final String name = createSetterName(aName);
- Map<Method, ParameterValues> setters = new HashMap<Method, ParameterValues>();
for (Method method : _setters.keySet()) {
- if (method.getName().equals(name)) {
+ if (method.getName().equals(aName)) {
_setters.remove(method);
return this;
}
}
throw new IllegalArgumentException(
- "No setter configured by the name of '" + aName + "'");
+ "No method configured by the name of '" + aName + "'");
}
+
+ /**
+ * Removes the method from the set of methods.
+ * @param aMethod Method to remove.
+ * @return
+ */
+ public SetterConfiguration remove(Method aMethod) {
+ if ( !aMethod.getDeclaringClass().isAssignableFrom(_class) ) {
+ throw new RuntimeException("Method " + aMethod + " not found in class " + _class + " or its superclasses");
+ }
+ for (Method method : _setters.keySet()) {
+ if (method.equals(aMethod)) {
+ _setters.remove(method);
+ return this;
+ }
+ }
+ throw new IllegalArgumentException(
+ "Method '" + aMethod + "' was not configured. ");
+ }
+
+
/**
* Creates the name of a setter based on the name of the setter without the
* Setter name.
* @return Setter name.
*/
- private String createSetterName(String aName) {
+ private String createxSetterName(String aName) {
return "set" + aName.substring(0, 1).toUpperCase() + aName.substring(1);
}
/**
* Adds a given setter name to the setters.
*
- * @param aName
+ * @param aName Name of a setter method.
* @return Reference to the current object to allow call chaining.
*/
- public SetterConfiguration add(String aName) {
- final String name = createSetterName(aName);
+ public SetterConfiguration add(final String aName) {
int oldlen = _setters.size();
List<Method> methods = new ArrayList<Method>();
CollectionFilter.filter(getAllSetters(_class, _publicOnly), methods,
new Condition<Method>() {
@Override
public boolean matches(Method aObject) {
- return aObject.getName().equals(name);
+ return aObject.getName().equals(aName);
}
});
if (methods.size() == 0 ) {
- throw new IllegalArgumentException("No setter found for '" + aName
- + "' in " + _class.getName());
+ throw new IllegalArgumentException("Method '" + aName
+ + "' not found in " + _class.getName());
}
// TODO is it possible to get more than one setter here in case the subclass overrides
// the baseclass method?
}
private static ParameterValues createParameterValues(Method method) {
+ // TODO generalize to multiple parameters.
return new ParameterValues(
- new String[] { getSetterName(method) }, new Class[] { method
+ new String[] { method.getName() }, new Class[] { method
.getParameterTypes()[0] });
}
* @return Parameter values.
*/
public ParameterValues values(String aMethod) {
- String name = createSetterName(aMethod);
for (Method method : _setters.keySet()) {
- if (method.getName().equals(name)) {
+ if (method.getName().equals(aMethod)) {
return _setters.get(method);
}
}
- throw new IllegalArgumentException("No setter method '" + name
+ throw new IllegalArgumentException("No setter method '" + aMethod
+ "' found");
}
* Method.
* @return Setter name.
*/
- private static String getSetterName(Method aMethod) {
+ private static String getxSetterName(Method aMethod) {
String result = aMethod.getName().substring(3);
return result.substring(0, 1).toLowerCase() + result.substring(1);
}
ClassConfiguration classConfig = new ClassConfiguration(X7.class);
classConfig.getConstructorConfig().select(Boolean.class);
- classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("port").setValue(0, 10);
+ classConfig.getObjectConfig().getSetterConfig().initAllSetters().values("setPort").setValue(0, 10);
ProvidedInterface providedBoolean = new DefaultProvidedInterface("boolean",
Boolean.class);
config.initAllSetters();
List<RequiredInterface> required = config.getRequiredInterfaces();
assertEquals(1, required.size());
- assertEquals("value", required.get(0).getName());
+ assertEquals("setValue", required.get(0).getName());
ProvidedInterface provided = new DefaultProvidedInterface("janse",
String.class);
}
});
assertEquals(2, required.size());
- assertEquals("value", required.get(0).getName());
- assertEquals("xyz", required.get(1).getName());
+ assertEquals("setValue", required.get(0).getName());
+ assertEquals("setXyz", required.get(1).getName());
ProvidedInterface providedString = new DefaultProvidedInterface(
"janse", String.class);
}
});
assertEquals(3, required.size());
- assertEquals("flag", required.get(0).getName());
- assertEquals("value", required.get(1).getName());
- assertEquals("xyz", required.get(2).getName());
+ assertEquals("setFlag", required.get(0).getName());
+ assertEquals("setValue", required.get(1).getName());
+ assertEquals("setXyz", 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("host", required.get(0).getName());
- assertEquals("port", required.get(1).getName());
+ assertEquals("setHost", required.get(0).getName());
+ assertEquals("setPort", 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("value", required.get(0).getName());
+ assertEquals("setValue", required.get(0).getName());
ProvidedInterface provided = new DefaultProvidedInterface("janse",
String.class);
public void testSetExplicitValue() {
SetterConfiguration config = new SetterConfiguration(X5.class).initAllSetters();
- config.values("value").setValue(0, "bladibla");
+ config.values("setValue").setValue(0, "bladibla");
List<RequiredInterface> required = config.getRequiredInterfaces();
assertEquals(0, required.size());
public void testAddByName() {
SetterConfiguration config = new SetterConfiguration(X6.class);
- config.clear().add("host");
+ config.clear().add("setHost");
List<RequiredInterface> required = config.getRequiredInterfaces();
Collections.sort(required, new RequiredInterfaceComparator());
assertEquals(1, required.size());
- assertEquals("host", required.get(0).getName());
+ assertEquals("setHost", 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("host", required.get(0).getName());
+ assertEquals("setHost", required.get(0).getName());
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
config.setNonPublic(true);
config.clear();
- config.add("xyz");
+ config.add("setXyz");
assertEquals(1, config.getRequiredInterfaces().size());
}
public void testRemove() {
SetterConfiguration config = new SetterConfiguration(X6.class).initAllSetters();
- config.remove("port");
+ config.remove("setPort");
List<RequiredInterface> required = config.getRequiredInterfaces();
Collections.sort(required, new RequiredInterfaceComparator());
assertEquals(1, required.size());
- assertEquals("host", required.get(0).getName());
+ assertEquals("setHost", required.get(0).getName());
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);