private Object[] fillResultWithAllParamProviderMethods(Class<?> sourceClass) { ArrayList<Object> result = new ArrayList<Object>(); while (sourceClass.getSuperclass() != null) { result.addAll(gatherParamsFromAllMethodsFrom(sourceClass)); sourceClass = sourceClass.getSuperclass(); } if (result.isEmpty()) throw new RuntimeException( "No methods starting with provide or they return no result in the parameters source class: " + sourceClass.getName()); return result.toArray(new Object[] {}); }
private ArrayList<Object> gatherParamsFromAllMethodsFrom(Class<?> sourceClass) { ArrayList<Object> result = new ArrayList<Object>(); Method[] methods = sourceClass.getDeclaredMethods(); for (Method method : methods) { if (method.getName().startsWith("provide")) { if (!Modifier.isStatic(method.getModifiers())) throw new RuntimeException( "Parameters source method " + method.getName() + " is not declared as static. Modify it to a static method."); try { result.addAll(Arrays.asList(processParamsIfSingle((Object[]) method.invoke(null)))); } catch (Exception e) { throw new RuntimeException( "Cannot invoke parameters source method: " + method.getName(), e); } } } return result; }