@Test public void testGetSetter() throws Exception { Context context = Mockit.setUpMock(new MockContext()); C c = new C(); Method m = Configurator.getSetter(c.getClass(), "b"); assertEquals(1, m.getParameterTypes().length); assertEquals(B.class, m.getParameterTypes()[0]); }
protected static Method getSetter(Class clazz, final String fieldId) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); String methodName = "set" + fieldId; for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw new NoSuchMethodException("No such public method (case insensitive): " + methodName + " in " + clazz); }
Configurator { protected static Method getSetter(Class clazz, final String fieldId) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); String methodName = "set" + fieldId; for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw new NoSuchMethodException("No such public method (case insensitive): " + methodName + " in " + clazz); } }
Configurator { protected static Method getSetter(Class clazz, final String fieldId) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); String methodName = "set" + fieldId; for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw new NoSuchMethodException("No such public method (case insensitive): " + methodName + " in " + clazz); }  }
Configurator { protected static Method getSetter(Class clazz, final String fieldId) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); String methodName = "set" + fieldId; for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw new NoSuchMethodException("No such public method (case insensitive): " + methodName + " in " + clazz); }  static void configure(Context ctx, Object obj, int xmlFileId); static void configure(Context ctx, Object obj, HashMap<String, String> params); }
Configurator { protected static Method getSetter(Class clazz, final String fieldId) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); String methodName = "set" + fieldId; for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName)) { return method; } } throw new NoSuchMethodException("No such public method (case insensitive): " + methodName + " in " + clazz); }  static void configure(Context ctx, Object obj, int xmlFileId); static void configure(Context ctx, Object obj, HashMap<String, String> params);  }